Python学习(1)

来源:互联网 发布:python hangman游戏 编辑:程序博客网 时间:2024/05/21 17:50

一、拼接字符串

>> "Hello, " + "world!"'Hello, world!'
Python中,字符串可以直接相加。而C++中,这是不行的,+操作符的左右操作数必须至少有一个是string类型,如

string str1 = "Hello";string str2 = str1 + "," + "world";   // okstring str3 = "world" + ", " + str1;  // errorstring str = "hello" + "world";       // error

str2中,左结合。


二、input 和 raw_input 的比较

raw_input会把输入作为原始数据放入字符串中,尽量使用raw_input。


三、原始字符串

原始字符串以r开头,其使用反斜线不会被转义,但是不能在原始字符串结尾输入反斜线。

>> print r"hello\"     // error>> print r"hello" "\\" // ok, you can do this, if you must add '\'



原创粉丝点击