Python_ List and Ganso

Source: Internet
Author: User

python_ list and Ganso

Author:Lxy




list (lists)
A list is a built-in data type of Python, and list is an ordered set of elements that can be added and removed at any time.
gets the list of elements to be obtained with a corner mark, a corner mark can use a positive angle, or you can use a negative angle, throw Indexerro when out of bounds
The data type of the elements in the list can also be different (just like in Java), or you can put another list within the list, which creates a multidimensional collection


Method of List
len (list) #获取lest长度
append () #末尾追加元素
pop () #弹出末尾元素
For example:
>>>zoo = [' Pig ', ' tiger ', ' dog ']
>>>zoo
[' Pig ', ' tiger ', ' dog ']
>>>zoo[0]
' Pig '
>>>zoo[-1]
' dog '

tuple (Ganso)
Ganso is also an ordered list, and the list is very similar, the difference is the tuple once defined can not be modified, in a sense this also improves the security of the code, the Query method and list, the use of a tuple can use a tuple.
Add "comma" when defining Ganso with 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 change, in fact the tuple does not change, the value of the internal list is changed.>>> country = (' BJ ', [' sh ', ' GD '])
>>> Country[1]
[' sh ', ' GD ']
>>> country[1][0] = ' yn '
>>> Country
(' BJ ', [' yn ', ' gd '])
>>>


from group:Java user groups

Python_ list and Ganso

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.