字符串
1.python中字符串连接使用\”+\”
text1 = \'hello\'
text2 = \' world\'
print text1+text2 //hello world
2.字符串表示
在python中将值转换为字符串有三种机制
Ⅰ.repr()
,将值以合法形式的Python表达式来表示值;
print \'hello world\' // hello world
print 1000L // 1000
直接打印出来的结果是不带双引号或者没有类型符的,如果使用repr()
print repr(\'hello world\') //\'hello world\'
print repr(1000L) //1000L
说明使用repr()就能将值转换为python合法形式表达式的字符串。
Ⅱ.str()
,将值转换为合理形式的字符串;
print str(1000L) //1000
print str(\'hello world\') //hello world
Ⅲ.使用``
将值包住也可以实现repr()的效果。
3.input()与raw_input()
input默认输入的值是合法的python表达式。
input(\'how are you?\')
>>>how are you? fine //name \'fine\' id no defined
raw_input会将输入的数据当做原始数据。
raw_input(\'how are you?\')
>>>how are you? fine // \'fine\'
4.长字符串
使用```
来代替引导就可以实现长字符串,长字符串可跨多行。