Application of list in Python

Source: Internet
Author: User

This article mainly introduces: the main application of the list in Python and some functions of the list comes with

Code:

#!/usr/bin/env python
# Author by LH
#-*-Coding:utf-8-*-
Name_list=[' al ', ' Ed ', ' FG ']
Print Name_list #打印列表

Print Name_list[0] #索引

Print Name_list[0:2] #切片

For i in Name_list: #for循环打印
Print I

Name_list.append (' Ed ') #添加
Print Name_list

I=name_list.count (' Ed ') #统计相同的字符有几个
Print I

temp=[' FG ', ' FG ', ' FG ']
Name_list.extend (temp) #批量添加
Print Name_list

Print Name_list.index (' al ')
#获取指定字符串的索引位置
Name_list.insert (1, ' SX ')
Print Name_list

A1=name_list.pop () #移除最后一个
Print A1

Name_list.remove (' Ed ') #移除想要删除的字符串 (the default is to remove the first from left to right if you have the same)
Print Name_list

Name_list.reverse () #将字符串反过来打印 (reverse)
Print Name_list
Del Name_list[0:4]       #删除指定位置的字符串 (both indexes and slices apply)
Print Name_list

Operation Result:




Application of list in 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.