The role of commas in note-python

Source: Internet
Author: User

1, use, remove the extra line break

>>> for I in Range (0,5):
... print I
...
0
1
2
3
4
>>> for I in Range (0,5):
... print I,
...
0 1 2) 3 4

It is obvious that the print statement defaults to a newline followed by a comma followed by a newline that becomes a space

After a comma is appended to the assignment expression, a tuple object is automatically obtained

>>> 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 ' >

2. The use of commas in type conversions is mainly the conversion of tuples
After a comma is added to the assignment expression, a tuple object is automatically obtained, and the desired result is not obtained when some type-related work or serialization is required. When you encounter a similar phenomenon in your work, you can put this into your own checklist.

>>> Print C
[]
>>> Print D
([],)
>>> Print a
1
>>> Print B
(2,)

3. Add it after the Django list,

The role of commas in note-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.