Python learning diary [2]

Source: Internet
Author: User

Tuple: (with ())

And list are different:

1, the list is more flexible, you can add the deletion of arbitrary elements, tuples once created can not be changed;

>>> dir (test)

[' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ' ', ' __getitem__ ', ' __getnewargs__ ', ' __getslice__ ', ' __gt__ ', ' __hash__ ', ' __init__ ', ' __iter__ ', ' __le__ ', ' __len__ ', ' __lt__ ', ' __mul__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __repr__ ', ' __rmul__ ', ' __setattr__ ', ' __ Sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' count ', ' index ']

>>> test[1:]

(2, 3, 4)

>>> Test[:3]

(1, 2, 3)

>>> test[1:]

(2, 3, 4)

>>> Test[:3]

(1, 2, 3)

P.S.

1. The types of elements in lists and elements are not qualified, can be nested, somewhat similar to jagged arrays

2. Slicing

Format Operation string:

1, similar to the C language in the printf class function requirements of the formatted input.

2, the escape of the format control character.

Sequence:

1, List (), New empty list

List (iterable), new list initialized from iterable ' s items

2. ZIP ()---the zip function accepts any number of sequences (including 0 and 1) as parameters, returning a tuple list.

Function:

Define DEF return_value function_name (parameters):

#函数实现

1, function nesting---python support function inline-function internal definition function;

2, Function closure---sub-function can use local variables in the parent function, this behavior is called closure!

Example plots

3. Expand Reading

Python learning diary [2]

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.