本文介绍了python 3打印功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想打印这个:

*
**
***
****
*****

我的代码是:

for row in range(1,6):
    for col in range(row):
        print('*', end="")
    print('')

我的问题是关于打印功能,因为它包括换行符.以前知道一些C,我无法弄清楚最后一个print('')的作用,以及为什么没有它我的代码无法工作.

My question is about print function, since it includes new line. Knowing some C before, I just can't figure it out what the last print('') does, and why my code doesn't work without it.

推荐答案

第一次调用printend=''参数禁止在*之后打印纽辛,而第二次调用print则仅打印换行符.

The end='' parameter to the first call to print suppresses printing a newine after the *, and the second call to print prints only a newline.

这篇关于python 3打印功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:31