python的“end=”介绍

  • Post author:
  • Post category:python


print默认是打印一行,结尾加换行。

end

=’ ‘意思是末尾不换行,加空格。

举例子:

from math import sqrt
def isprime(x):
    if x==1:
        return False
    k=int(sqrt(x))
    for j in range(2,k+1):
        if x%j==0:
            return False
    return True

for i in range(2,101):
    if isprime(i):
        print(i,end=' ')###第一类输出
        print(i)###第二类输出

输出:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

输出:

2

3

5

7

11

13

17

19

23

29

31

37

41

43

47

53

59

61

67

71

73

79

83

89

97

Process finished with exit code 0



版权声明:本文为zouxiaolv原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。