This example describes the role of commas after Python assignment statements. Share to everyone 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 (a) <type ' int ' > >>> print type (b) <type ' Tuple ' > >>> c = [] >>> d = [], >>> print type (c) <type ' list ' > >>> print type (d) <type ' tuple ' > |
After a comma is appended to an assignment expression, an tuple object is automatically obtained, and the desired result is not obtained when doing some type-related work or requiring serialization. You can put this into your own checklist when you encounter something like a supernatural phenomenon in your work.
?
| 1 2 3 4 5 6 7 8 |
>>> print C [] >>> print D ([],) >>> print a 1 >>> print B (2,) |
I hope this article will help you with your Python programming.