逗号,用于生成一个长度为1的元组

>>> (1)
1
>>> (1,)
(1,)
>>> 1,
(1,)

因此需要将长度为1的元组中元素提取出来可以用,简化赋值操作

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
>>> a=(1,)
>>> b=a
>>> b
(1,)
>>> b,=a
>>> b
1

最后print打印变量加,实现连续打印不换行的操作在python3中行不通了

Python 3.7.3 (default, Nov 15 2019, 04:04:52) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(0,5):
...     print(i)
... 
0
1
2
3
4
>>> for i in range(0,5):
...     print(i,)
... 
0
1
2
3
4
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄