码迷,mamicode.com
首页 > 编程语言 > 详细

python变量加逗号,的含义

时间:2020-02-21 23:59:59      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:edits   元组   需要   逗号   help   变量   copy   code   int   

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

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

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

>>> 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

python变量加逗号,的含义

标签:edits   元组   需要   逗号   help   变量   copy   code   int   

原文地址:https://www.cnblogs.com/azureology/p/12343730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!