Python Class C Array of two forms: List--content variable, tuple---> content is not mutable

Source: Internet
Author: User

The list in Python is quite the same as the array in C, List: Lists initialized using [], tuple: tuple initialized using ();


A list of lists

1 #!/usr/bin/python
2
3 #list初始化: []
4 classmate = [' s ', ' su ', ' Sum ', ' sume ', ' Sumey '];
5
6 print classmate;
7 print classmate[0]; #第一个元素: S
8 print classmate[-5]; # negative, i.e. from right to left: s
9 Print classmate[(len (classmate)-1)]; #classmate [4]; Positive number, that is, from left to right: Sumey


#append Append
Classmate.append (' Hi ');
Print classmate;


#replace replacement
CLASSMATE[5] = ' Hallo ';
Print classmate;


#insert Insert
Classmate.insert (0, ' world ');
Print classmate;


#delete Delete
Classmate.pop (-1);
Print classmate;


#multi Inline
p = [' A ', ' B '];
Q = [' 1 ', ' 2 ', ' 3 ', p];
Print q;
Print q[3];
Print q[3][1];


Second, tuple tuple


Python Class C Array of two forms: List--content variable, tuple---> content is not mutable

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.