首页 > 编程语言 > 详细

python: practice string method

时间:2020-03-08 09:06:39      阅读:68      评论:0      收藏:0      [点我收藏+]

str=‘hello world‘

str.startswith(‘he‘)

str.endswith{‘y"}

str.expendtabs()

st=‘he \t llo world‘

st.expandtabs(tabsize=10)

st.find(‘e‘)       :find first element and return index value

st.format(0) : formatting  string  assignment element for value

   usage:  for example  :st=‘hello kitty {‘name‘}‘   st.format(name=‘alan‘)

    st=‘hello world {name} is {age}‘

    st.format(name=‘alan‘,age=30)

st.format_map({})

st.index(‘h‘)

 

st.isalnum()   ;include alphabet and number ,contain alphabet and digit

st.isdecimal():     judage one string whether a decimal digit

st.isdigit()   judage element whether number integery

st.isnumeric() judage element whether numeric

‘afs123‘.isidentifier()  judage element whether alphabet

‘aa‘.islower()

‘AAA‘.isupper()

‘  ‘=.isspace()

‘My sister.istitle() first alphabet capital

‘My siste.lower()   all alphabet lower case

‘my sister.upper()  all alphabet  capital

‘my sister.swapcase() twist alphabet capital or lower case

‘my.sister‘.ljust

‘my sister‘.strip() .delete  front or rear space,line break \n

st.lstrip()

st.rstrip()

st.replace(‘a‘,‘b‘)

st.rfind(‘t‘)

st.lfind(‘t‘)

st.split(‘ ’):for example   ‘hello kitty‘.split(‘i‘)   hello k i  tty

st.rsplit(‘i‘,1)

 

st.title().   first capital 

 

python: practice string method

原文:https://www.cnblogs.com/alansuny/p/12439452.html

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