首页 > 编程语言 > 详细

python学习:字符串操作

时间:2015-01-27 21:58:02      阅读:214      评论:0      收藏:0      [点我收藏+]

1:双引号转义

<span style="font-size:18px;"><strong>print "he\"llo"</strong></span>
只需要在双引号前面加一个反斜杠。

输出结果:he"llo


2:字符串的拼接

(1)可以用+号

<span style="font-size:18px;"><strong>print "hello" +" "+ "wolrd"</strong></span>

(2)可以用逗号

<span style="font-size:18px;"><strong>print "hello","world"</strong></span>

(3)可以用*数字

<span style="font-size:18px;"><strong>print "hello"*3</strong></span>

输出结果:

hello wolrd
hello world
hellohellohello


3:字符串长度

<span style="font-size:18px;"><strong>print len("hello")</strong></span>

使用len()函数。输出结果5


4:类型转换:字符串转int

<span style="font-size:18px;"><strong>print int("111") + 1</strong></span>
输出结果 112


5:类型转换:int转字符串

<span style="font-size:18px;"><strong>print "aaa" + str(1)</strong></span>

使用函数str

输出结果:aaa1




python学习:字符串操作

原文:http://blog.csdn.net/u013628152/article/details/43202069

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