python学习--13 基本数据类型 2
2020-12-13 02:41
标签:code nis pre nsa 分割 基本 空格 dsa 运算 接上次补充: 运算结果: 其他功能: 1. 运算结果: 2. 运算结果: 运算结果: 3.判断字符串里是否全是空格 运算结果: 4.判断是否是标题(首字母大写) 运算结果: 5.变成标题 运算结果: 6. 运算结果: 7.填充 运算结果: 8.只用00填充 运算结果: 9. 运算结果: 10. 运算结果: 11.去掉空白(换行\n,空格\t也能去掉) 12.移除指定字符串 运算结果: 13.分割 运算结果: 14. 运算结果: 15. 运算结果: 16.大小写转换 运算结果: python学习--13 基本数据类型 2 标签:code nis pre nsa 分割 基本 空格 dsa 运算 原文地址:https://www.cnblogs.com/liujinjing521/p/11047756.htmls = "username\temail\tpassword\naaa\taa@qq.com\t123\nusername\temail\tpassword\naaa\taa@qq.com\t123"
a = s.expandtabs(20) #断句,以20为单位,不够就自动补齐20个
print(a)
username email password
aaa aa@qq.com 123
username email password
aaa aa@qq.com 123
Process finished with exit code 0
#判断当前输入是否为数字
test = ‘②‘
a1 = test.isdecimal() #仅支持数字
a2 = test.isdigit() #支持特殊符号和数字
a3 = test.isnumeric() #支持所有包括中文
print(a1,a2,a3)
False True True
Process finished with exit code 0
test = ‘sjalfaj\tafaaf‘
a1 = test.isprintable() # 是否存在不可显示的字符
print(a1)
False
Process finished with exit code 0
test = ‘sjalfajafaaf‘
a1 = test.isprintable() # 是否存在不可显示的字符
print(a1)
True
Process finished with exit code 0
test = ‘sjalfa jafaaf‘
a1 = test.isspace() # 是否全是空格
print(a1)
False
Process finished with exit code 0
test = ‘sjalfa jafaaf‘
a1 = test.istitle()
print(a1)
False
Process finished with exit code 0
test = ‘sjalfa jafaaf‘
a1 = test.istitle()
a2 = test.title()
print(a1)
print(a2)
False
Sjalfa Jafaaf
Process finished with exit code 0
#将字符串中的每一个元素按照指定分隔符进行拼接
test = ‘你好啊猪头‘
print(test)
t = ‘ ‘
a = t.join(test) #或者 把t.join(test)改成‘ ‘.join(test)
print(a)
你好啊猪头
你 好 啊 猪 头
Process finished with exit code 0
test = ‘abcd‘
a = test.ljust(20,‘*‘)
a1 = test.center(20,‘中‘)
print(a)
print(a1)
abcd****************
中中中中中中中中abcd中中中中中中中中
Process finished with exit code 0
test = ‘abcd‘
a = test.zfill(20)
print(a)
0000000000000000abcd
Process finished with exit code 0
test = ‘ABCD‘
a = test.islower() # 判断是否为小写
a1 = test.lower() # 全部变成小写
print(a,a1)
False abcd
Process finished with exit code 0
test = ‘abcd‘
a = test.isupper() # 判断是否为大写
a1 = test.upper() #变成大写
print(a,a1)
False ABCD
Process finished with exit code 0
test = ‘ abcd ‘
a = test.lstrip() # 去掉左边空白
#a1 = test.rstrip() #去掉右边空白
#a2 = test.strip() # 去掉全部空白
print(a)
test = ‘abcd‘
a = test.lstrip("a")
print(a)
bcd
Process finished with exit code 0
test = ‘lovesdcvvf‘
a = test.partition(‘v‘) #只能将整个字符串分割成3份
a1 = test.rpartition(‘v‘) #从右开始分割成3份
a2 =test.split("v",2) #全部分割
a3 = test.rsplit() #从右开始全部分割
print(a)
print(a1)
print(a2)
print(a3)
(‘lo‘, ‘v‘, ‘esdcvvf‘)
(‘lovesdcv‘, ‘v‘, ‘f‘)
[‘lo‘, ‘esdc‘, ‘vf‘]
[‘lovesdcvvf‘]
Process finished with exit code 0
test = ‘adfsdf\nsafafsad\ndsaf‘
a = test.splitlines(True) # 只能根据换行分割, 布尔值用来是否显示换行符
print(a)
[‘adfsdf\n‘, ‘safafsad\n‘, ‘dsaf‘]
Process finished with exit code 0
test = ‘adfsdf\nsafafsad\ndsaf‘
a = test.startswith(‘a‘) #判断是否以a开头的
b = test.endswith("a") #判断是否以a结尾
print(a)
print(b)
True
False
Process finished with exit code 0
test = ‘abc‘
a = test.swapcase()
print(a)
ABC
Process finished with exit code 0