Examples of the three functions of comma in Python, and analysis of python instances
This example describes the three functions of comma in Python. Share it with you for your reference. The specific analysis is as follows:
Recently I have encountered a comma problem in python, but I haven't figured it out yet.
1. Use of commas in parameter transmission:
In this case, the comma between parameters is not confusing.
For example, def abc (a, B) or abc (1, 2)
2. The use of commas in type conversion is mainly the conversion of tuples.
For example:
>>> A = 11 >>> B = (a) >>> b11 >>> B = (a,) >>> B (11,) >>> B = (a, 22) >>> B (11, 22) >>> B = (a, 22,) >>> B (11, 22)
It can be seen that only when there is only one element in the B tuples, you need to use commas to convert them to the tuples.
3. The usage of commas in the print output statement:
Example:
>>> For I in range (0, 5 ):... print I... 01234 >>> for I in range ):... print I ,... 0 1 2 3 4
Obviously, by default, the print statement adds a line break followed by a comma, and the line feed becomes a space.
I hope this article will help you with Python programming.