码迷,mamicode.com
首页 > 编程语言 > 详细

Python字符串相关操作

时间:2017-12-31 10:58:32      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:mutable   abc   let   nbsp   error:   pre   ble   body   tom   

字符串操作练习:

>>> ‘\‘No!\‘,Tom didn\‘t want to join them. ‘ #使用斜杠来避免引号冲突
"‘No!‘,Tom didn‘t want to join them. "
>>> ‘abc‘*3
‘abcabcabc‘
>>> words = ‘Let\‘s make the world a better place!‘
>>> len(words)
36
>>> words[35]
‘!‘
>>> words[20:33]
‘ a better pla‘
>>> words[-10:]
‘ter place!‘
>>> words[1]=‘D‘ #String is immutable
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ‘str‘ object does not support item assignment

 

Python字符串相关操作

标签:mutable   abc   let   nbsp   error:   pre   ble   body   tom   

原文地址:https://www.cnblogs.com/rhyswang/p/8153790.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!