Python3.7知其然知其所以然-第六章 字符串(11)


s = \"you are A handsome guy.\"

# 第一个字母转为大写其他的全为小写

print(s.capitalize())

6.9字符串倍数

Python字符串 , 可通过*来输出倍数字符串内容 , 像“good”*  3 表示输出3次good 。 可用乘法赋值运算符:*= 精简表示 。

# 字符串内容

s1 = \"good\"

count = 3

# 输出倍数字符串内容

s1 = s1 * count

print(s1)

# 通过乘法赋值运算符输出?

s2 = \"nice\"

s2 *= count

print(s2)

6.10字符串补齐

推荐阅读