标签:lower lex 首字母 hello 输出 pac art 元素 统计
if age.isdigit(): #字符串age是数字”12”
age = int(age)
else:
exit() #退出程序
exit(“现在我退出了”)
print(‘helloworld‘[2:])
print(‘el‘ in ‘hello‘)
%s %d %f
msg = ‘‘‘name =%s,age =%s‘‘‘%(name,age)
d2=‘--‘.join([a,b]) # 123-- abc
print( st.count(内容) ) # 统计元素个数
print( st.endswith(‘tty3‘) ) # 判断是否以某个内容结尾
print( st.startswith(‘he‘) ) # 判断是否以某个内容开头
print(st.find(‘t‘)) # 查找到第一个元素,并将索引值返回
print(‘My title title‘.rfind(‘t‘))
print(‘\tMy tLtle\n‘.strip()) #去换行符,空格
print(‘\tMy tLtle\n‘.lstrip())
print(‘\tMy tLtle\n‘.rstrip())
print(‘My title title‘.replace(‘itle‘,‘lesson‘,1)) #把itle替换为lesson ,替换几次
print(‘My title title‘.split(‘i‘,1)) #仅以第一个i为分隔符
print( st.capitalize() ) # 首字母大写
print(‘Abc‘.islower())
print(‘ABC‘.isupper())
print(‘ e‘.isspace())
print(‘ tLtle‘.lower())
print(‘tLtle‘.upper())
print(‘My tLtle‘.swapcase()) #大写变小写,小写变大写
print( st.center(50,‘#‘) ) # 居中 长度50,#填充
print(‘My tLtle‘.ljust(50,‘*‘)) #左
print(‘My tLtle‘.rjust(50,‘*‘)) #右
print(‘My tLtle‘.title()) #每个单词首字母大写
-------------------------------------------------------------------------------
摘一些重要的字符串方法
print(st.count(‘l‘))
print(st.center(50,‘#‘)) # 居中
print(st.startswith(‘he‘)) # 判断是否以某个内容开头
print(st.find(‘t‘))
print(st.format(name=‘alex‘,age=37)) # 格式化输出的另一种方式
print(‘My tLtle‘.lower())
print(‘\tMy tLtle\n‘.strip())
print(‘My title title‘.replace(‘itle‘,‘lesson‘,1))
print(‘My title title‘.split(‘i‘,1))
标签:lower lex 首字母 hello 输出 pac art 元素 统计
原文地址:https://www.cnblogs.com/5014sy/p/9774497.html