Python day2 list Tuple dictionary string

Source: Internet
Author: User
Tags iterable pop value shallow copy

List

#列表事例

>>> li = List ((1,2,3,4,5))
>>> Print Li
[1, 2, 3, 4, 5]


>>> li2 = [' A ', ' B ', ' C ', ' d ']
>>> Print Li2
[' A ', ' B ', ' C ', ' d ']
>>>

#列表尾部增加元素
>>> Li.append (6)
>>> Li
[1, 2, 3, 4, 5, 6]


#清空列表内的元素, suitable for py3
Li.clear ()
Print (LI)
[]


#列表的拷贝 (in-depth copy) (ignored)
Li = [1,2,3,4,]
Li3 = Li.copy ()
Li3.append (678,)
Print (LI)
Print (LI3)
liid = ID (li)
LIID3 = ID (li3)
Print (LIID,LIID3)

[1, 2, 3, 4]
[1, 2, 3, 4, 678]
35707080 35737992

#extend合并两个列表或者把列表和元组合并
>>> Li.extend ([up])
>>> Li
[1, 2, 3, 4, 5, 6, 1, 2]

#count判断某个元素出现的次数
>>> Li.count (1)
2


#index获取列表内元素的索引下表
>>> Li.index (6)
5


#insert指定下标, inserting elements
>>> Li.insert (2, ' abc ')
>>> Li
[1, 2, ' abc ', 3, 4, 5, 6, 1, 2]

#pop移除某一项, add subscript
>>> Li
[1, 2, ' abc ', 3, 4, 5, 6, 1, 2]
>>> res = Li.pop (3)
>>> Print Res
3
>>> Print Li
[1, 2, ' abc ', 4, 5, 6, 1, 2]

#remove删除--pop value, Pop is added subscript
>>> li.remove (' abc ')
>>> Li
[1, 2, 4, 5, 6, 1, 2]


#reverse反向排序
>>> Li
[1, 2, 4, 5, 6, 1, 2]
>>> Li.reverse ()
>>> Li
[2, 1, 6, 5, 4, 2, 1]

#sort排序
>>> Li
[2, 1, 6, 5, 4, 2, 1]
>>> Li.sort ()
>>> Li
[1, 1, 2, 2, 4, 5, 6]
>>>

English introduction

classList (object):"""list (), New empty list List (iterable), new list initialized from iterable ' s items"""    defAppend (self, p_object):#real signature unknown; restored from __doc__        """L.append (object), None--Append object to end"""        Pass    defClear (self):#real signature unknown; restored from __doc__        """l.clear (), None--Remove all items from L"""        Pass    defCopy (self):#real signature unknown; restored from __doc__        """l.copy () List--a shallow copy of L"""        return []    defCount (self, value):#real signature unknown; restored from __doc__        """L.count (value), integer--return number of occurrences of value"""        return0defExtend (self, iterable):#real signature unknown; restored from __doc__        """L.extend (iterable), None--extend list by appending elements from the iterable"""        Pass    defIndex (self, value, Start=none, Stop=none):#real signature unknown; restored from __doc__        """L.index (value, [Start, [stop]]), integer-return first index of value.        Raises valueerror if the value is not present. """        return0defInsert (self, Index, p_object):#real signature unknown; restored from __doc__        """L.insert (Index, object)--Insert object before index"""        Pass    defPop (self, index=none):#real signature unknown; restored from __doc__        """l.pop ([index]), item-Remove and return item at index (default last).        Raises indexerror If list is an empty or index is out of range. """        Pass    defRemove (self, value):#real signature unknown; restored from __doc__        """L.remove (value), None--Remove first occurrence of value.        Raises valueerror if the value is not present. """        Pass    defReverse (self):#real signature unknown; restored from __doc__        """L.reverse ()--Reverse *in place*"""        Pass    defSort (self, key=none, reverse=false):#real signature unknown; restored from __doc__        """L.sort (Key=none, Reverse=false), None--stable sort *in place*"""        Pass
View Code


Dictionary

Tomorrow continued ~ ~

Python day2 list Tuple dictionary string

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.