zl程序教程

您现在的位置是:首页 >  Python

当前栏目

python中如何重复打印很多遍?

2023-03-20 15:28:34 时间

python中如何重复打印很多遍?

python中重复打印很多遍的方法:

1、使用多个print()函数进行打印

strings = "a" # 字符串变量
print(strings)
print(strings)
print(strings)
print(strings)

输出结果如下:

python中如何重复打印很多遍?

2、使用循环

strings = "a" # 字符串变量
for i in range(3):
    print(strings)

结果如下:

python中如何重复打印很多遍?

3、在输出函数中将要输出的内容*n

strings = "a" # 字符串变量
print(strings * 5)

结果如下:

python中如何重复打印很多遍?

数字的话要预处理一下:

numbers = 8
print(numbers * 5)
print(str(numbers) * 5)

python中如何重复打印很多遍?

更多Python知识请关注Python视频教程栏目。