字符串长度
>>> a = 'hello python'>>> len(a)12
字符串取值从0开始
>>> a[0]'h'
>>> a[1]'e'
>>> a[-1]'n'
后一位不包括
>>> a[2:4]'ll'
>>> a[2]'l'>>> a[4]'o'
取全部
>>> a[:]'hello python'
>>> a[4:]'o python'>>> a[:-1]'hello pytho'
重复
>>> a'hello python'>>> a * 3'hello pythonhello pythonhello python'
>>> a = a * 3>>> a'hello pythonhello pythonhello python'
>>> a *= 3>>> a'hello pythonhello pythonhello pythonhello pythonhello pythonhello pythonhello pythonhello pythonhello python'
本文分享自微信公众号 - 从零开始的linux(gh_4a9d788f5f27),作者:零月
原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。
原始发表时间:2017-04-07
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
我来说两句