首页 > 其他 > 详细

输出字符串即长度计算

时间:2016-07-30 10:30:54      阅读:181      评论:0      收藏:0      [点我收藏+]

方法一:单引号

‘http‘

方法二:双引号

"http"

方法三:三引号

"""http"""

输出单引号:"let‘s go"

输出双引号:‘she say "yes使用转移符"\"

>>>print(‘she said "yes! let\‘s go"‘)

>>>print("she said \"yes! let‘s go\"")

 

 

字符串长度计算len(s):

>>>len("pear")

4

>>>len(‘pear‘)

4

>>>len(‘‘)

0

>>>len(‘you are‘) 空格也算一个字符,不管前中后

7

 

字符串拼接(+),拼接后输出也是字符串:

>>>‘hot‘+‘ dog‘

‘hot dog‘

>>>‘one ‘+"two "+‘three‘

‘one two three‘

多次拼接(*):

>>>‘he‘*3 或者3*‘hehe‘

‘hehehe‘

>>>len(‘good‘+boy)*‘it‘

ititititititit

输出字符串即长度计算

原文:http://www.cnblogs.com/yunman/p/5720338.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!