filmov
tv
Dictionary Function in Python | get, pop, popitem, keys, values, items, fromkeys, update, setdefault
Показать описание
In this video we will discuss about Dictionary in Python.
Dictionary is a Mutable Object
Dictionary is a Mapping (Key : Value)
Dictionary is a Collection of key & value pair
Dictionary key are immutable & unique
Dictionary value can be anything, it can store any type of value
Dictionary elements are ordered, changeable & allows duplicate in value only
{} (Curly Brackets) are used in Dictionary
Eg. d = {1:'Ford' , 2:'Ferrari' , 3:'Pagani' , 4:'Maruti'}
We will also learn about True Copy and Shallow Copy
True Copy - True copy of a data is duplicate data of the original data, hence when making any changes in one copy it does not show/reflect in the other copy
Shallow copy - Here 2 or more variables hold same reference to the data item, therefore changes made by one variable in the data reflects in all the other variable holding the reference of the data.
We will also learn following Dictionary Functions :-
clear() Removes all the elements from the dictionary
copy() Returns a copy of the dictionary
fromkeys() Returns a dictionary with the specified keys and value
get() Returns the value of the specified key
items() Returns a list containing a tuple for each key value pair
keys() Returns a list containing the dictionary's keys
pop() Removes the element with the specified key
popitem() Removes the last inserted key-value pair
setdefault() Returns the value of the specified key. If the key does not exist: insert the key, with the specified value
update() Updates the dictionary with the specified key-value pairs
values() Returns a list of all the values in the dictionary
Dictionary is a Mutable Object
Dictionary is a Mapping (Key : Value)
Dictionary is a Collection of key & value pair
Dictionary key are immutable & unique
Dictionary value can be anything, it can store any type of value
Dictionary elements are ordered, changeable & allows duplicate in value only
{} (Curly Brackets) are used in Dictionary
Eg. d = {1:'Ford' , 2:'Ferrari' , 3:'Pagani' , 4:'Maruti'}
We will also learn about True Copy and Shallow Copy
True Copy - True copy of a data is duplicate data of the original data, hence when making any changes in one copy it does not show/reflect in the other copy
Shallow copy - Here 2 or more variables hold same reference to the data item, therefore changes made by one variable in the data reflects in all the other variable holding the reference of the data.
We will also learn following Dictionary Functions :-
clear() Removes all the elements from the dictionary
copy() Returns a copy of the dictionary
fromkeys() Returns a dictionary with the specified keys and value
get() Returns the value of the specified key
items() Returns a list containing a tuple for each key value pair
keys() Returns a list containing the dictionary's keys
pop() Removes the element with the specified key
popitem() Removes the last inserted key-value pair
setdefault() Returns the value of the specified key. If the key does not exist: insert the key, with the specified value
update() Updates the dictionary with the specified key-value pairs
values() Returns a list of all the values in the dictionary