Python赋值语句后逗号的作用分析
发布时间:2020-12-16 23:47:52 所属栏目:Python 来源:网络整理
导读:本篇章节讲解Python赋值语句后逗号的作用。供大家参考研究。具体分析如下: IDLE 2.6.2 a = 1 b = 2, print type(a)type 'int' print type(b)type 'tuple' c = [] d = [], print type(c)type 'list' print type(d)type 'tuple' 赋值表达式的后面加了
本篇章节讲解Python赋值语句后逗号的作用。分享给大家供大家参考。具体分析如下: IDLE 2.6.2 >>> a = 1 >>> b = 2,>>> print type(a) <type 'int'> >>> print type(b) <type 'tuple'> >>> c = [] >>> d = [],>>> print type(c) <type 'list'> >>> print type(d) <type 'tuple'> 赋值表达式的后面加了逗号后,会自动得到一个tuple的对象,在作一些与类型相关的工作或需要序列化时,是不能得到期望的结果的。工作中碰到类似灵异现象时,可以把这个放到自己的checklist中了。 >>> print c [] >>> print d ([],) >>> print a 1 >>> print b (2,) 希望本文所述对大家的Python程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |