数字与表达式——字符串

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












  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值