Python Road (ii)--list, Yuan Zu, dictionary

Source: Internet
Author: User
Tags function prototype iterable

Some of the functions defined within the list
    • Append: Adds a new object at the end of the list.

      Function prototypes: def append (self, p_object)

      Usage:

      List1.append (P_object)

    • Clear: Empty list

      Function prototype: def clear (self)

      Usage:

      List1.clear ()

    • Count: Count the number of occurrences of an element in a list

      Function prototypes: def count (self, value)

      Usage:

      List1.count (value)

  • Extend: Appends multiple values from another sequence at the end of the list (expands the original list with a new list)

    Function prototypes: def extend (self, iterable)

    Usage:

    List1.extend (iterable)

  • Extend: Appends multiple values from another sequence at the end of the list (expands the original list with a new list)

    Function prototypes: Def index (self, value, Start=none, Stop=none)

    Usage:

    List1.extend (iterable)

  • Index: Find a value from the list where the first occurrence of a match is indexed, no error is found

    Function prototypes: Def index (self, value, Start=none, Stop=none)

    Usage:

    List1.index (value,m,n) Find value in #在 [m,n) interval

  • Insert: Inserting an object into a list

    Function prototypes: def insert (self, index, p_object)

    Usage:

    List1.insert (Index,object)

  • Pop: Deletes an object, deletes the last one by default, and returns the object

    Function prototypes: Def pop (self, index=none)

    Usage:

    List1.pop (Index)

  • Remove: Deletes a specified object

    Function prototype: def remove (self, value)

    Usage:

    List1.remove (value)

  • Reverse: Reverse List

    Function prototype: def reverse (self)

    Usage:

    List1.reverse ()

  • Sort: Sorting the original list

    Function prototypes: def sort (self, key=none, reverse=false)

    Usage:

    List1.sort (Key,reverse)

Ganso Some functions defined within a tuple
    • Count: The number of members in the statistics meta-ancestor

      Function prototypes: def count (self, value)

      Usage:

      Tuple.count (value)

    • Index: Find the index position of the first occurrence of a value from the meta-ancestor, no error found

      Function prototypes: Def index (self, value, Start=none, Stop=none)

      Usage:

      Tuple1.index (value,m,n) Find value in #在 [m,n) interval

Some functions defined within the dictionary Dict
    • Clear: Clears the contents of the dictionary

      Function prototype: def clear (self)

      Usage:

      Dict1.clear ()

    • Fromkeys: Create a new dictionary

      Function prototypes: Def fromkeys (*args, **kwargs)

      For example:

seq = ( ' hello ',  ' hello ',  ' python ') Dict1 = Dict.fromkeys (SEQ) print (dict1) Dict1 = Dict.fromkeys (seq, 10) print (dict1)  #输出结果为 #{' Hello ': None, ' World ': None, ' Python ': none} #{' Hello ': ten, ' World ': Ten, ' Python ': ten}         
    • Get: Returns the value of the specified key, if the value does not return a D value in the dictionary, the default is None

      Function prototype: def get (self, k, d=none)

      Usage:

      Dict1.get (k,d)

    • Items: Returns a traversed (key, value) tuple array

      Function prototype in a list: def items ( Self)

      Usage:

      Dict1.items ()

    • Keys: Returns a dictionary with a list all keys

      Function prototype: def Keys (self)

      Usage:

      Dict1.keys ()

    • Pop: Delete the value of the dictionary given key key, the return value is the deleted value. The key value must be given, if no key found, to return the D

      Function prototype: def pop (self, k, d=none)

      Usage:

      Dict1.pop (k,d)

    • Popitem: Delete last pair of keys and values in Dictionary

      Function prototype: def popitem (self)

      Usage:

      Dict1.popitem ()

    • SetDefault: Similar to get (), but if the key does not exist in the dictionary, the key will be added and the value will be set to default

      Function prototypes: Def setdefault (self, k, d=none)

      Usage:

      Dict1.setdefault (K,D)

    • Update: Updates the key/value pairs of another dictionary into this dictionary

      Function prototypes: def update (self, e=none, **f)

      Usage:

      Dict1.update (DICT2)

    • Values: Returns all values in the dictionary as a list

      Function prototypes: def values (self)

      Usage:

      Dict1.values ()

Python Road (ii)--list, Yuan Zu, dictionary

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.