字符串str的使用方法

参考:https://www.cnblogs.com/cookie1026/p/6048092.html
#!/usr/bin/env python
# -*- coding:utf-8 -*-
s = 'abcd'
ss = 'this is cash'
print s.ljust(7,'w')#返回一个原字符串右用字符串0填充左对齐并宽度7的新字符串
print s.rjust(6,'-')
print s.center(20,'*')#表示原字符串居中两边填充宽度的用法
print ss.center(20,' ')

print format(ss,'.3')

本文主机介绍了字符串的使用,可以进行字符串切片、统计字符串长度、查找、替换、大小写转换等。

打印结果如下:

猜你喜欢

转载自www.cnblogs.com/longesang/p/10406096.html