List common actions

Source: Internet
Author: User

About the role of a list: In one variable, one of the values can be easily stored

The list has some attribute methods, and two underscores can be forgotten

>>> name=[' Veigar ', ' Pengchun ' Zhangxuan ']

>>> Dir (name)

[' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __delitem__ ', ' __delslice__ ', ' __doc__ ', ' __eq__ ', ' __format_ ' _ ', ' __ge__ ', ' __getattribute__ ', ' __getitem__ ', ' __getslice__ ', ' __gt__ ', ' __hash__ ', ' __iadd__ ', ' __imul__ ', ' __init_ _ ', ' __iter__ ', ' __le__ ', ' __len__ ', ' __lt__ ', ' __mul__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __repr__ ' , ' __reversed__ ', ' __rmul__ ', ' __setattr__ ', ' __setitem__ ', ' __setslice__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ' ', ' append ', ' count ', ' extend ', ' index ', ' Insert ', ' pop ', ' remove ', ' reverse ', ' sort ']


List has the attributes:


############# #索引 ##############

name = [,,] (name[]) (name[]) (name[])
Output result veigarpengchunzhangxuan########################


############# #指定往最后一个元素后追加字符 ##############

name = [,,] <== Note: This append is appended to the last element after name. () (name)
Output results [' Veigar ', ' Pengchun ', ' Zhangxuan ', ' Jack ']########################################



############ #指定往特定的字符后面添加字符 ##############

name = [,,]name.insert (,) (name)

The result of the output

[' Veigar ', ' Pengchun ', ' Pengchun ', ' Zhangxuan ']

######################################################




################## #指定最后一个元素删除 #############

name = [,,]name.pop () (name)

Output results

[' Veigar ', ' Pengchun ']

####################################################




################ #指定某个元素删除 ##################

name = [,,]name.remove () (name)
Output results [' Veigar ', ' Zhangxuan ']
#########################################



############### #查看一个列表中相同元素的值有多少 ################

name = [,,]name.insert (,) (Name.count ())
Output Result: 2#################################################



################ #循环 #########################################

name = [,,,]i (Name.count ()): <== represents the element to be deleted from a list name.remove () (name)

Output results

[' Veigar ', ' Zhangxuan ']

#############################################################




#################### #关于列表切片 ################################

name = [,,,,,]b=name[:] (b) <== only takes digital output [1, 2, 3, 4]##################################################


################## #关于extend将两个列表放在一起 ###################

name = [,,,]=[,]name.extend () (name)

Output results

[1, 2, 3, 4, ' A ', ' B ']

#################################################################

List common actions

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.