Examples of the three functions of comma in Python, and analysis of python instances

Source: Internet
Author: User

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.

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.