The print function and the list function in Python

Source: Internet
Author: User

Print () function:

The default carriage return when passing in a single parameter, the keyword end can be used to avoid the output after the carriage return ( newline ), or to end the output with a different string.

>>> A, b = 0, 1>>> while B <: ...     Print (b, end= ', ')     ... A, B = B, a+b ... 1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
When multiple parameters are passed in, the output is separated by a space between multiple parameters.
>>> i = 256*256>>> print (' The value of I ', I) the value of I is 65536

List

It can be written as a comma-delimited list of values (items) in square brackets. Items in a list do not need to be of the same type.

Characteristics:

Just like the string index, the index of the list starts with 0, the list can be sliced, connected, and so on:

All slice operations return a new list containing the requested element

Unlike a string that is immutable *, it is possible to change a single element in the list. It is also possible to assign a value to a slice, which can even change the size of a string, or completely erase it:

The built-in functions are len() also valid for lists

Nested lists (creating lists that contain other lists) are possible,

You can add something to the end of the list:

>>> q = [2, 3]>>> p = [1, q, 4]>>> len (p) 3>>> p[1][2, 3]>>> p[1][0]2>>& Gt P[1].append (' Xtra ') >>> p[1, [2, 3, ' Xtra '], 4]>>> q[2, 3, ' Xtra ']

In the last example, p[1] and q indeed point to the same object! We will go back to * object semantics *.

The print function and the list function 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.