赞
踩
st = ' hello python '
print(st)
print(st.strip())
输出结果:
hello python
hello python
st = ' hello python '
print(st)
print(st.lstrip())
输出结果:
hello python
hello python
st = ' hello python '
print(st)
print(st.rstrip())
输出结果:
hello python
hello python
st = ' hello python '
print(st)
print(st.replace('python', 'word'))
输出结果:
hello python
hello word
通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串
(包括多个空格,制表符\t,换行符\n等)分割,并返回所有分割得到的字符串
st = ' hello python '
print(st)
print(st.split('python'))
st = ' hello \n python '
print(st)
print(st.split())
输出结果:
hello python
[' hello ', ' ']
['hello', 'python']
st = ' hello python '
print(st)
tt = st.split()
t2 = ''.join(tt)
t3 = ','.join(tt)
print(t2)
print(t3)
输出结果:
hello python
hellopython
hello,python
st = 'HELLO PYTHON'
print(st.lower())
输出结果:
hello python
st = 'hello python'
print(st.upper())
输出结果:
HELLO PYTHON
st = 'hello python'
print(st.title())
输出结果:
Hello Python
st = 'Hello Python'
print(st.swapcase())
输出结果:
hELLO pYTHON
st = 'hello python'
print(st.capitalize())
输出结果:
Hello python
st = 'hello\npython'
print(st)
输出结果:
hello
python
st = 'hello\rpython'
print(st)
输出结果:
python
st = 'hello\tpython'
print(st)
输出结果:
hello python
st = 'hello\bpython'
print(st)
输出结果:
hellpython
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。