How do you separate multiple expressions with commas in Python development (http://www.maiziedu.com/course/python-px/) ? I've previously explained how to print an expression using print, whether it's a string or another type of string that is automatically converted. print multiple expressions using print and you can separate them with commas:
>>> print "Age", 19
Age 19
As you can see, a space character is inserted between each parameter.
Note: The print parameters do not form a tuple as we expected:
>>> 1, 2, 3
(1, 2, 3) >>> print 1, 2, 3
1 2 3
>>> print (1, 2, 3)
(1, 2, 3)
This feature is useful if you want to output text and variable values at the same time, but do not want to use string formatting:
>>> name = "Xuhoo"
>>> salutation = "Mr."
>>> greeting = "Hello,"
>>> print greeting, salutation, name
Hello, Mr Xuhoo.
Note that if the greeting string does not have a comma, how can you get a comma in the result? It is not possible to do this as follows:
>>> print Greeting, ",", Salutation, name
Hello, Mr Xuhoo.
# Because the above statement adds a space before the comma. Here's a solution:
>>> Print Greeting + ",", Salutation, name
Hello, Mr Xuhoo.
# in this way, only a comma is added after the greeting.
If you add a comma at the end, the next statement will be printed on the same line as the previous statement, for example:
Print "Hello", print "world!"
# Output Hello, world! ( This only works in scripts, and in interactive Python There is no effect in the session. In an interactive session, all statements are executed separately ( and the content is printed ))
What are the methods for exporting comma-delimited in python?