Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
61 views

Python Notes

This document provides notes on common dictionary methods and functions in Python including Dict(), len(), del, copy(), deepcopy(), fromkeys(), has_key(), items(), iteritems(), key(), pop(), popitem(), setdefault(), update(), and values(). It also covers checking if a key is in a dictionary with "in", clearing a dictionary with clear(), and checking if a string ends with another string using endswith().

Uploaded by

Samridhi Sam
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Python Notes

This document provides notes on common dictionary methods and functions in Python including Dict(), len(), del, copy(), deepcopy(), fromkeys(), has_key(), items(), iteritems(), key(), pop(), popitem(), setdefault(), update(), and values(). It also covers checking if a key is in a dictionary with "in", clearing a dictionary with clear(), and checking if a string ends with another string using endswith().

Uploaded by

Samridhi Sam
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Python notes: Dict() function is used to construct dictionaries.

Len(d) returns no of items in d D[k]=v associates value v with k Del d[k] deletes item with key k K in d checks whether there is any element corresponding to key k Clear() removes all items from dictionary Copy() returns a new dictionary with same key value pairs. Deepcopy() is a method that prevents any changes from happening in the original dictionary if tried in the copied one. Fromkeys() method creates a new dictionary with the given keys each with a default corresponding value of None. Has_key() checks whether a dictionary has a given key. Items() returns all the items of the dictionary as a list of items. Iteritems() works in the same way bt returns iterator instead of list. Key() method returns a list of keys. Pop() removes key-value pair from dictionary and returns the value. Popitem() pops off the last element of a list. Setdefault() sets the value corresponding to a given key. Update() method updates one dictionary with the items of another. Values() returns a list of the values in the dictionary. A colon(:) indicates that a block of code is about to begin Endswith("string") checks whether a string ends with the given string as the argument.

You might also like