Python字符串魔法(一)
Python 字符串魔法 1. expandtabs(num) 1 testStr = "name\temail\tage\nxiaohua\t12345@qq.com\t22\nxiaoshuai\t54321@qq.com\t23\nxiaozhang\t67890@qq.com\t24\t" 2 print(testStr.expandtabs(15)) 输出:1 C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\python.exe E:/Python/PyProject/Study.py 2 name email age 3 xiaohua 12345@qq.com 22 4 xiaoshuai 54321@qq.com 23 5 xiaozhang 67890@qq.com 24 说明:expandtabs(num)用于查找字符串中\t(制表符)并将其剩余长度用空格补充,如上面例子所示 num = 20,查找到第一个\t时,前面字符串name长度为4,则后面16长度将由16个空格填充。 2. isalpha() 1 testStr = "hello world" 2 print(testStr.isalpha()) #判断字符串是否为全为字母 全字母返回true 3.isdight() ,