print('hello world'.capitalize()) #让第一个单词首字母大写
print('hello world'.upper()) #全大写
print('hello world'.lower()) #全小写
print('hello world'.title()) #每个单词的首字母大写
#ljust,rjust ljust(width,fillchar) 长度和填充的字符,默认是空格
print('hello'.ljust(10))
print('hello'.ljust(10,'-'))
print('hello'.rjust(10))
print('hello'.rjust(10,'-'))
#居中
print('hello'.center(20))
print('hello'.center(20,'*'))
#去空格
print(' hello '.lstrip())
print('-----hello-----'.lstrip('-'))
print(' hello '.rstrip())
print(' hello '.strip())
names = 'zhangsan+lisi+wangwu+tom+jerry'
name = names.split('+')
print(name)
fruits = ['banana','apple','grape','pear','orange']
print('-'.join(fruits))
print('*'.join('hello'.title()))
word = 'hello'
x = input('请输入一个字符:')
for h in word:
if x == h:
print('您输入的内容存在')
break
else:
print('您输入的内容不存在')
name = 'Curry'
age = 32
print('大家好,我的名字叫',name,'今年',age,'岁了',sep='')
# print('大家好,我的名字叫 %s,今年%d岁了,'(name,age))
#字符串的format方法
#{}用来占位
x = '大家好,我的名字叫做{},今年{}岁了'.format('Curry',32)
print(x)
#{数字} 根据数字的顺序进行填入,从0开始
x = '大家好,我的名字叫做{1},今年{0}岁了'.format(32,'Curry')
print(x)
#{变量名}
x = '大家好,我的名字叫做{name},今年{age}岁了'.format(name = 'Curry',age = 32)
print(x)
#{数字}{变量}混合使用
x = '大家好,我的名字叫做{name},今年{0}岁了'.format(32,name = 'Curry')
print(x)
结果
Hello world
HELLO WORLD
hello world
Hello World
hello
hello-----
hello
-----hello
hello
*******hello********
hello
hello-----
hello
hello
['zhangsan', 'lisi', 'wangwu', 'tom', 'jerry']
banana-apple-grape-pear-orange
H*e*l*l*o
请输入一个字符:132
您输入的内容不存在
大家好,我的名字叫Curry今年32岁了
大家好,我的名字叫做Curry,今年32岁了
大家好,我的名字叫做Curry,今年32岁了
大家好,我的名字叫做Curry,今年32岁了
大家好,我的名字叫做Curry,今年32岁了
Process finished with exit code 0