全部版块 我的主页
论坛 提问 悬赏 求职 新闻 读书 功能一区 学习笔记1.0
558 0
2015-05-04
Python strings come with a powerful set of processing tools. Python has no distinct type for individual characters; instead you just
use one-character strings.

Strings are derived from sequences, and are immutable. It is easy enough to digest with examples:

S = ''   # empty string with single quotes
S ="spam's"  # double quotes
S ='s\n\p\ta\x00m'  # escape
S=""" ...multipline .."""  # triple-quoted block strings
S=r'\tmp\spam' # Raw strings (no escapes"
S=b'sp\xc4m'  # byte strings
S=u'sp\u00c5m'  # Unicode
S1+S2 # concatenation
S*3  
S[i]
S[i:j]
len(S)
"a %s parrot" % kind   # string formatting expression
S.find('pa')
S.rstrip()  # remove whitespace
S.replace('pa','xx')
S.split(',')
S.isdigit()
S.lower()
S.endswith('spam')
'spam'.jjoin(strlist)  # delimiter join
for x in S: print(x)  # iteration
'spam' in S
[c*2 for c in S]
map(ord, S)
re.match('sp(.*)am', line)  # pattern matching: library module


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群