Python fifth day

Source: Internet
Author: User

Lists List

Add Append

A = ['shangsan','Lisi']a.append ('  Wangwu')  ## #wangwu增加到尾部

Insert insertion (by index)

A = ['b','C']a.insert (1,'d'   # ## # #d插入到列表1的位置The result is: ['b','D  ','C']

Addition of Extend iterations

A = ['a','b','C']a.extend ('MNL') The result is: ['a','b','C','m','N','L']

Deletion of the list

Pop is deleted by index and has a return value

A = ['a','b','c',' D ' ]a.pop (2) The result is ['a','b', ' D ']

Remove removes elements directly

A = ['a','b','C']m.remove (  'a')

Del Delete by index can be sliced delete

A = ['a','b','c',' D ' ]del a[0:1]

Clear Empty List

Changes to the list

Delete First, iterate to add

Direct assignment according to the index

A = ['a','b','C'  D' result is ['d','b ','C']

Count List counts

Sort (list is ordered and can be sorted by index)

Sort positive Order

A = [1,5,8,4,6,3,4]a.sort ()print(a)  ## #按照大小顺序

Reverse reverse (reverse, from rear to front)

Reverse (in order) A.sort (rever=true)

The list is converted into a string join

A = ['a','b','C']  Print('*'. Join (a))  ### ' * ' delimiter

The result is: a*b*c

Python fifth day

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.