商城设计app网站建设,陈木胜去世,可以做100张照片的软件,天津招投标 天津建设工程信息网一、ljust()
语法#xff1a;str.ljust(width,[fillchar]) 参数说明#xff1a; width – 指定字符串长度。 fillchar – 填充字符#xff0c;默认为空格。 返回值#xff1a;返回一个原字符串左对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于原字符串…一、ljust()
语法str.ljust(width,[fillchar]) 参数说明 width – 指定字符串长度。 fillchar – 填充字符默认为空格。 返回值返回一个原字符串左对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于原字符串的长度则返回原字符串。 str this is string example....wow!!!
print(str.ljust(50, 0))
# this is string example....wow!!!00000000二、rjust()
语法str.rjust(width,[fillchar]) 参数说明 width – 指定字符串长度。 fillchar – 填充字符默认为空格。 返回值返回一个原字符串右对齐并使用空格填充至长度 width 的新字符串。如果指定的长度小于原字符串的长度则返回原字符串。 str this is string example....wow!!!
print(str.rjust(40, 0))
# 00000000this is string example....wow!!!三、zfill(width)
语法str.zfill(width) width – 指定字符串的长度。原字符串右对齐前面填充0。 返回长度为 width 的字符串原字符串 string 右对齐前面填充0 str this is string example....wow!!!
print(str.zfill(40))
# 00000000this is string example....wow!!!
print(str.zfill(50))
# 000000000000000000this is string example....wow!!!四、string.center(width)
语法str.center(width, [fillchar]) width – 字符串的总宽度。fillchar – 填充字符。 返回一个原字符串居中并使用空格填充至长度width的新字符串如果不指定填充字符默认填充符为空格 str runoob
print(str.center(20, *))
# *******runoob*******
print(str.center(20))
# runoob