Python _ list and ancestor

Source: Internet
Author: User

Python _ list and ancestor
Python _ list and ancestor

Author: lxy




List)
A list is a built-in data type of Python. A list is an ordered set that allows you to add and delete elements at any time.
Obtain the elements in the list using the badge. You can use the badge or the negative badge. If the badge is out of the range, IndexErro is thrown.
The Data Types of elements in the list can be different (just like Java), or another list can be placed in the list, which forms a multi-dimensional set.


List Method
Len (list) # obtain the lest Length
Append () # append Element
Pop () # elements at the end of the pop-up
For example:
>>> Zoo = ['pig', 'tiger ', 'Dog']
>>> Zoo
['Pig', 'tiger ', 'Dog']
>>> Zoo [0]
'Pig'
>>> Zoo [-1]
'Dog'

Tuple)
Yuanzu is also an ordered list, which is very similar to list. The difference is that once tuple is defined, it cannot be modified. In a sense, this improves the code security. The query method is the same as list, tuple is used when tuple is used.
Add a comma when defining the ancestor of only one element to avoid ambiguity with mathematical operations.


Variable tuple
When a list is placed inside the ancestor, the value of the list in the ancestor can be changed. In fact, tuple has not changed, change the value of the internal list >>> country = ('bj ', ['sh', 'gd'])
>>> Country [1]
['Sh', 'gd ']
>>> Country [1] [0] = 'yny'
>>> Country
('Bj ', ['yn', 'gd '])
>>>


From group: Java User Group

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.