接上次补充:

s = "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

其他功能:

1.

#判断当前输入是否为数字
test = '②'
a1 = test.isdecimal() #仅支持数字
a2 = test.isdigit() #支持特殊符号和数字
a3 = test.isnumeric() #支持所有包括中文
print(a1,a2,a3)

运算结果:

False True True

Process finished with exit code 0

2.

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

3.判断字符串里是否全是空格

test = 'sjalfa   jafaaf'
a1 = test.isspace() # 是否全是空格
print(a1)

运算结果:

False

Process finished with exit code 0

4.判断是否是标题(首字母大写)

test = 'sjalfa   jafaaf'
a1 = test.istitle()
print(a1)

运算结果:

False

Process finished with exit code 0

5.变成标题

test = 'sjalfa   jafaaf'
a1 = test.istitle()
a2 = test.title()
print(a1)
print(a2)

运算结果:

False
Sjalfa Jafaaf Process finished with exit code 0

6.

#将字符串中的每一个元素按照指定分隔符进行拼接
test = '你好啊猪头'
print(test)
t = ' '
a = t.join(test) #或者 把t.join(test)改成' '.join(test)
print(a)

运算结果:

你好啊猪头
你 好 啊 猪 头 Process finished with exit code 0

7.填充

test = 'abcd'
a = test.ljust(20,'*')
a1 = test.center(20,'中')
print(a)
print(a1)

运算结果:

abcd****************
中中中中中中中中abcd中中中中中中中中 Process finished with exit code 0

8.只用00填充

test = 'abcd'
a = test.zfill(20) print(a)

运算结果:

0000000000000000abcd

Process finished with exit code 0

9.

test = 'ABCD'
a = test.islower() # 判断是否为小写
a1 = test.lower() # 全部变成小写 print(a,a1)

运算结果:

False abcd

Process finished with exit code 0

10.

test = 'abcd'
a = test.isupper() # 判断是否为大写
a1 = test.upper() #变成大写 print(a,a1)

运算结果:

False ABCD

Process finished with exit code 0

11.去掉空白(换行\n,空格\t也能去掉)

test = '   abcd    '
a = test.lstrip() # 去掉左边空白
#a1 = test.rstrip() #去掉右边空白
#a2 = test.strip() # 去掉全部空白
print(a)

12.移除指定字符串

test = 'abcd'
a = test.lstrip("a") print(a)

运算结果:

bcd

Process finished with exit code 0

13.分割

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

14.

test = 'adfsdf\nsafafsad\ndsaf'
a = test.splitlines(True) # 只能根据换行分割, 布尔值用来是否显示换行符
print(a)

运算结果:

['adfsdf\n', 'safafsad\n', 'dsaf']

Process finished with exit code 0

15.

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

16.大小写转换

test = 'abc'
a = test.swapcase()
print(a)

运算结果:

ABC

Process finished with exit code 0

最新文章

  1. js跨域访问
  2. maven错误:Project configuration is not up-to-date with pom.xml
  3. Eclipse中使用Git-让版本管理更简单
  4. 关于phpstudy安装的问题
  5. 整合jQuery和Prototype遇到的问题.
  6. Android JNI 由C/C++本地代码向Java层传递数据
  7. java Active Object模式(上)
  8. 关于链接target的问题
  9. ComboBox绑定数据源时触发SelectedIndexChanged事件的处理办法
  10. DNS解析详细过程
  11. yum upgrade卡在 清理initial-setup-0.3.9.30-1.el7.centos.x86_64
  12. Hitchhiker 是一款开源的 Restful Api 测试工具
  13. mysql 创建表指定 字符类型与存储引擎
  14. org.apache.http.TruncatedChunkException: Truncated chunk ( expected size: 47956; actual size: 35656)
  15. rsyn同步软链接保持不变
  16. cf-Global Round2-D. Frets On Fire(二分)
  17. Docker container常用命令
  18. js数组遍历 千万不要使用for...in...
  19. “Hello World!”团队第五周第三次会议
  20. XSS的原理分析与解剖(第二篇)[转]

热门文章

  1. 为centos7配置阿里yum源遇到的问题以及解决方法
  2. [转]js创建1-100的数组
  3. Linux -- 如何减少IO过程中的CPU copy
  4. [Feature] Feature selection
  5. 123457123456#0#-----com.twoapp.KidsShiZi01--前拼后广--儿童宝宝识字jiemei
  6. LeetCode_122. Best Time to Buy and Sell Stock II
  7. [Vue warn]: Do not use built-in or reserved HTML elements as component id: content
  8. 为何有DAO与Service层?为何先搞Dao接口在搞DaoImpl实现?直接用不行吗?
  9. 关于新小米盒子的Recovery模式如何进入
  10. Levenberg-Marquardt迭代(LM算法)-改进Guass-Newton法