python菜鸟学习: 5.字符串的基本用法,进度条显示
# -*- coding: utf-8 -*-
import sys,time
str1 = "my name is liyuzhoupan"
# 首字母大写
print(str1.capitalize())
# 统计字符串中的字符出现的次数
print(str1.count("n"))
# 自动补齐多少位,不够的用字符#替代
print(str1.center(50, "-"))
# 判断是否已字符“pan”为结尾
print(str1.endswith("pan"))
# 输出tab建
print(str1.expandtabs(tabsize=20))
# 格式化
print("my name is {name} ,age {age}".format(name="liyuzhoupan", age=23))
# 判断是否为阿拉伯字符或者数字
print("123adsf".isalnum())
# 判断是否为整数
print("123".isdigit())
# 判断是否大写
print("NAME".isupper())
# 字符转大写
print("name".upper())
# 字符转小写
print("NAME".lower())
# 替换字符串的中值
p = str.maketrans("abcdefj", "原来你是个人才")
print("my name is coffe".translate(p))
# 替换字符串中的值
print(str1.replace("m", "A", 1))
# 字符切割
print(str1.split(" "))
print(str1.split(" "))
#进度条展示
for i in range(10):
sys.stdout.write(">")
sys.stdout.flush()
time.sleep(0.1)
for i in range(100):
sys.stdout.write( "\r" +">" * i + "[{index}%]".format(index=i).rjust(100 - i, "_"))
sys.stdout.flush()
time.sleep(0.1)
for i in range(100):
k = i + 1
str = '>'*i+' '*(100-k)
sys.stdout.write("\r"+str+'[%s%%]'%(i+1))
sys.stdout.flush()
time.sleep(0.1)
本文来自博客园,作者:鲤鱼洲畔,转载请注明原文链接:https://www.cnblogs.com/liyuzhoupan/p/16588350.html