为字符串定义长度,如不满足,缺少的部分用 0 填充
newstr = string.zfill(width)
width
: 新字符串希望的宽度
# coding:utf-8
heart = 'love'
if __name__ == '__main__':
print(' t ' + heart)
print('t ' + heart)
print(heart.zfill(10))
print(heart.zfill(9))
print(heart.zfill(8))
print(heart.zfill(6))
print(heart.zfill(4))
返回当前字符串中某个成员 (元素) 的个数
inttpe = string.count(item)
item
: 查询个数的元素
# coding:utf-8
info = '''
The mission of the Python Software Foundation is to promote,
protect, and advance the Python programming language,
and to support and facilitate the growth of a diverse and
international community of Python programmers.
'''
a = info.count('a')
b = info.count('b')
c = info.count('c')
d = info.count('d')
e = info.count('e')
f = info.count('f')
print(a, b, c, d, e, f)
number_list = [a, b, c, d, e, f]
print(number_list)
print('在列表中最大的数值是', max(number_list))
number_dict = {
'a': a,
'b': b,
'c': c,
'd': d,
'e': e,
'f': f,
}
print('每个成员对应的数值分别是', number_dict)
文章作者: Zkeq
文章链接: https://cloud.tencent.com/developer/article/2006115
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。 转载 请注明来自 Zkeq の Coding 日志!