What are the methods for exporting comma-delimited in python?

Source: Internet
Author: User

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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.