2.输出结果自动换行的问题

 1 def print_multiples(n, high):
 2     i = 1
 3     while i <= high:
 4         print (n*i,'	',end='')
 5         i += 1
 6 
 7 def print_mult_table(high):
 8     i = 1
 9     while i <= high:
10         print_multiples(i, high)
11         print('
')
12         i += 1
13 if __name__ == '__main__':
14     print_mult_table(7)

第四行中加入的end=''就是为了解决输出结果自动换行的问题。加了就是以下输出结果:

 1 1     2     3     4     5     6     7     
 2 
 3 2     4     6     8     10     12     14     
 4 
 5 3     6     9     12     15     18     21     
 6 
 7 4     8     12     16     20     24     28     
 8 
 9 5     10     15     20     25     30     35     
10 
11 6     12     18     24     30     36     42     
12 
13 7     14     21     28     35     42     49     

但是如果不加就不会这样排列,而是每一行一个数字。

另外 是table,在python中是四个空格的距离, 是换行。

原文地址:https://www.cnblogs.com/lixiaofou/p/7594257.html