List of Python []

Source: Internet
Author: User
A list is a mutable type of data structure that is defined using the brackets.
strings are defined in quotation marks, and tuples are defined with parentheses, and the list is defined using brackets.

In [27]: list1=[]                  #创建一个空的列表In [28]: type(list1)Out[28]: listIn [29]: list2=list()             #也可以通过list函数创建一个空的列表In [30]: list2Out[30]: []In [31]: type(list2)Out[31]: list

Append: Adding elements to the list

In [33]: list2.append("a")    In [34]: list2Out[34]: [‘a‘]In [35]: list2.append("b")In [36]: list2Out[36]: [‘a‘, ‘b‘]

Delete

In [39]: list2Out[39]: [‘a‘, ‘b‘, ‘cdewd‘, ‘qewq‘]In [40]: del list2[-1]                  #删除列表中最后一个元素In [41]: list2        Out[41]: [‘a‘, ‘b‘, ‘cdewd‘]In [42]: list2.remove(list2[2])   #删除列表中下标为2的元素In [43]: list2Out[43]: [‘a‘, ‘b‘]

List of Python []

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.