python的print换行与不换行
程序员文章站
2022-07-13 23:38:10
...
python中print不换行
print不换行
- 不换行
>>>print('hello',end='')#一个空代表不换行相连
>>>print('world')
helloworld
>>>print('hello',end=' ')#两个空代表不换行有间隔
>>>print('world')
hello world
>>>print('hello',end='!')#!代表不换行以!相连
>>>print('world')
hello!world
- 换行
>>>for i in range(1,3):
>>> print('{} x2 = {}'.format(i,1*i),end=' ')
>>>print('')
>>>for i in range(1,4):
>>> print('{} x3 = {}'.format(i,1*i),end=' ')
>>>
1 X 2 = 2 2 X 2 = 4
1 X 3 = 3 2 X 3 = 6 3 X 3 = 9
一个小练习:打印九九乘法表
>>>for i in range(1,10):
>>> for j in range(1,i+1):
>>> print('{} x{} = {}'.format(j,i,i*j),end=' ')
>>> print('')
- 结果为