Analysis of the role of a comma after a value assignment statement in Python
This example describes the role of a comma after a value assignment statement in Python. Share it with you for your reference. The specific analysis is as follows:
IDLE 2.6.2
?
1 2 3 4 5 6 7 8 9 10 11 12 |
>>> A = 1 >>> B = 2, >>> Print type () <Type 'int'> >>> Print type (B) <Type 'tuple'> >>> C = [] >>> D = [], >>> Print type (c) <Type 'LIST'> >>> Print type (d) <Type 'tuple'> |
After a comma is added to the value expression, a tuple object is automatically generated. Expected results cannot be obtained when type-related work or serialization is required. When you encounter a similar spirit phenomenon in your work, you can put this in your own checklist.
?
1 2 3 4 5 6 7 8 |
>>> Print c [] >>> Print d ([],) >>> Print 1 >>> Print B (2 ,) |
I hope this article will help you with Python programming.