print(' ',end = '')
temp = input('请输入一个整数:')number = int(temp)
while number:
i = number - 1
while i:
print(' ', end = '')
i = i - 1
j = number
while j:
print('*', end = '')
j = j - 1
print()
number = number - 1
请问这串代码的print里面的内容是什么意思,一个循环结束后为什么会换行。 print()默认是打印完字符串会自动添加一个换行符,end=" "参数告诉print()用空格代替换行 本帖最后由 笨鸟学飞 于 2020-10-27 22:28 编辑
help(print)
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
======以上是函数帮助文档======
sep=' ' #意思你函数内输入多个参数,默认用空格隔开
end='\n' #意思你函数内结尾不自定义参数,则默认用换行结尾
======验证=================
>>> print(1,2,3)
1 2 3
>>> print(1,2,3,sep='')#自定义sep=空字符串,而不是默认的空格
123
>>> print('hello world',end='\n\n')#比默认的多一个换行符
hello world
#换了2行
>>> print('hello world')
hello world
页:
[1]