"Python-2.7.12" list type

Source: Internet
Author: User

List is one of the data types in Python, which is "lists". In Python we can insert, delete, modify, and so on the list type.

##新建list类型>>> ball = ['Volleyball','Basketball','Football','Baseball']##可以直接打印出list内容>>>ball['Volleyball','Basketball','Football','Baseball']##也可以使用下标列出, note that the subscript is starting from 0, and the negative number indicates the forward>>>Ball[0]'Volleyball'>>> ball[1]'Basketball'>>> ball[2]'Football'##使用append函数, append content to the list last>>> Ball.append ('Ping-Pong')>>>ball['Volleyball','Basketball','Football','Baseball','Ping-Pong']##选择位置插入, such as inserting ' badminton ' after ' volleyball '>>> Ball.insert (1,'Badminton')>>>ball['Volleyball','Badminton','Basketball','Football','Baseball','Ping-Pong']##替换list中的某一个元素, such as replacing ' badminton ' with ' bowling '>>> ball[1]='Bowling'>>>ball['Volleyball','Bowling','Basketball','Football','Baseball','Ping-Pong']##使用pop () Delete the element, such as deleting the last ' ping-pong ', deleting ' bowling '>>>Ball.pop ()'Ping-Pong'>>>ball['Volleyball','Bowling','Basketball','Football','Baseball']>>> Ball.pop (1)'Bowling'>>>ball['Volleyball','Basketball','Football','Baseball']##使用len () query the number of elements in list>>>ball['Volleyball','Basketball','Football','Baseball']>>>len (Ball)4

"Python-2.7.12" list type

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.