Learn about Python's list and tuple today

Source: Internet
Author: User

   1:  "'
   2:   arrays have list and tuple points
   3:  "'
   4:  
   5:  classmates=[' A ', ' B ', ' C ', ' d ']
   6:  print (classmates)
   7:  Length=len (classmates)
   8:  print (length) #4
   9:  print (classmates[0]+classmates[1]) # AB
  :  #print (classmates[5]) #IndexError: List index out of range
One   :  print (classmates[-1]) #! The index of the last element is-1
  :  classmates.append (#在最后加个元素88)
  :  print (classmates)
  :  classmates.insert (2,45)
  :  "'
  :      Add a 45 to the second position
  :  "
  :  print (classmates)
  :  Classmates.pop (-2)
  :  "'
Seven   :   Delete the second-to-last    element
A   :  "'
At   :  print (classmates)
  :  a=[[1,2,3],[4,5,6],[7,8,9]]
  :  print (a)
  £ º  
  :  
  :  "
  :  Tuple cannot change, once definition cannot be changed. Once a tuple is defined, the element must be fixed.
  :  "'
  :  classmates= (' A ', ' B ', ' C ')
  :  p=[' asp ', ' php '
  :  s=[' python ', ' Java ', p, ' scheme '
  :  print (s[2][1])
  :  a= ()
A   :  print (a)
  Panax notoginseng  :#定义只有一个元素的tuple的时候必须在定义后面加一个 ","
  :  a= (1,)
Section   :  print (a)
Max   :  "'
All   :   output is (1,)
"   :  "
  :  
  :  a= (1)
  :  Print (a) #输出为1
#但是这样可以变:   
A   :  l= (' A ', ' B ', [up])
  :  print (L)
  :  l[2].append (54)
  :  print (L)
  Wuyi:  #但这样变的只是L中的tuple.
  :  L = [
  :      [' Apple ', ' Google ', ' Microsoft ',
Si   :      [' Java ', ' Python ', ' Ruby ', ' PHP '],
  :      [' Adam ', ' Bart ', ' Lisa ']
  :  ]
  £ º  print (l[0][0],l[1][1],l[2][2])

Learn about Python's list and tuple today

Related Article

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.