Problems with Python basic data types

Source: Internet
Author: User

About indexes and slices in Python:

This is described in the previous view: The index value starts with 0, and 1 is the starting position from the end.

And then suddenly today, with a sense of clairvoyant, the index value starts with 0: that is, from left to right, increment by 0. -1 is from the end of the start position: that is, from right to left with-1 to start diminishing. For example:

      

1 ' python ']

Then: a[0] = 1, a[1] = 2, a[2] = 3, a[3] = ' python '

A[-1] = ' python ', a[-2] = 3, a[-3] = 2, a[-4] = 1

Dictionary: Define a dictionary

dict{'name':'wanan'code': ' LQ ' ' site ':'love'}

By calling the key output value, finally find using the Dict.get () function to complete

Dict.get ('name')'wanan'        # output result 

The following are the other operations of the dictionary:

Method Name Operation
Dict.clear () Delete all elements in a dictionary
Dict.copy () Returns a copy of the dictionary (shallow copy)
DICT.FROMKEYSC (Seq,val=none) Creates and returns a new dictionary that is the key to the dictionary with the elements in the SEQ, and Val does the initial value for all the keys in the dictionary (the default is None if this value is not provided)
Dict.get (Key,default=none) The key to the dictionary dict, returns the value it corresponds to, and returns the value of default if the key does not exist in the dictionary (note that the default value of the parameter is None)
Dict.has_key (Key) Returns True if the key (key) exists in the dictionary, otherwise false is returned. After the Python2.2 version introduced in and not, this method is almost obsolete, but still provides a working interface.
Dict.items () Returns a list that contains a tuple (key, value) in the dictionary
Dict.keys () Returns a list containing the keys in the dictionary
Dict.values () Returns a list that contains all the values in the dictionary
Dict.iter () Methods Iteritems (), Iterkeys (), and itervalues () are the same as the non-iterative methods they correspond to, but they return an iteration instead of a list.
Dict.pop (key[, default]) Similar to the method get (), if the key key exists in the dictionary, delete and return Dict[key], the Keyerror exception is thrown if the key key does not exist and the value of default is not given.
Dict.setdefault (Key,default=none) Similar to Method set (), if the key key is not present in the dictionary, it is assigned by Dict[key]=default.
Dict.setdefault (Key,default=none) Similar to Method set (), if the key key is not present in the dictionary, it is assigned by Dict[key]=default.

Problems with Python basic data types

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.