1、单引号字符串和转义字符
"Let's go!"
Out[3]: "Let's go!"
'"Hello world" she said'
Out[4]: '"Hello world" she said'
转义字符
'Let\'s go'
Out[8]: "Let's go"
"\"Hello,world\" she said"
Out[9]: '"Hello,world" she said'
2、拼接字符串
就如同加法运算一样
x= "Hello,"
y = "world"
x + y
Out[16]: 'Hello,world'
"Hello," + "World"
Out[18]: 'Hello,World'
3、字符串表示,str和repr
值被转换成字符串 的两种机制, str 会把值转换成合理形式的字符串 ,repr会创建一个字符串。它以合法的python表达式来标示值
(1)
print repr("Hello,world")
'Hello,world'
print str("Hello,world")
Hello,world
(2)
print repr(10000L)
10000L
print str(100000L)
100000
(3)
repr(x)的功能也可以用(`x`)实现(注意,`是反引号,而不是单引号——`是键盘1前面的按钮,英文输入法就出来了)
temp = 42
print "The temperature is " + `temp`
The temperature is 42
temp = 0
print "The temperature is " + repr(0)
The temperature is 0