Data types Tuples ,Sets, Dictionaries :

In python data types  sets ,Dictionaries and Tuples are easy to implement and and many of predefined function and modules are support them.

hello friend in this chapter we will discuss the more interesting python data types such as Tuples, sets, Dictionaries.In python . Tuples are smiler to list but it is immutable ,can convert from list to Tuple and vice versa

tuple(list)

list(tuple)

 

now if we looked at the buffer variable  you will noticed that this has been converted into Tuple the clear indication is little curly bracket “the sequence unpacking is the whole idea is that to unpack  each of the item to a apporiate variable for future use ” see example.

yow will see every variable is has own data item we have assigned

Sets :

 

Sets is nothing but a unordered collection of unique objects Now if we see in java language set and list are used is used in head ,array binary tree or many more.
if we create a set to list

x= set (y)

and vice versa
y=list(x)
lets see how its work

tuples in python

Set operations :

 

set operation is very common operation and used many times i thing so  set is nothing but a collection of unique item and perform a certain task or operation.we are not go in detail we use set operation and little idea about the how the operation will perform and what output we want
Union  : x|y
Intersection : x&y
Difference : x-y

for example

set operation in python

 

Dictionaries :

 

the Dictionaries is the one of he most important topic  we will discuss Dictionaries is Unordered Ket-value pairs.Keys are unique and immutable object like (string and numbers) the value of the key is change at any time there are ifferent ways to create a dictionaries
like

dict={}                   empty Dictionariey

dict[‘name’]=’vipin’

dict(name=’vipin’,’CFO’ =’buffercode’)

dict={‘name ‘ : ‘vipin’ , ‘CFO’ : ‘buffercode}

 

lets see how its work

Dictionaries  in python
dict.has_key(key)

key can be name ,CFO or othe you can take dict is a name of Dictionari you can change it int another one. we can you key in many type  one is above method and second is
‘key’ in dict
in key you can enter the key value you can find and dict is name of Dictionary

Dictionary Operations :

 

1 tuple of items : dict.items()
2 list of keys : dict.keys()
3 list of values :dict.values()
4 for a particular item : dict.get(key)

for item deletion

if you want to delete all items in Dictionary ew can use

-> dict.claer()

delete one item from Dictionary

-> del dict[key]

if you want to help  you can use

-> help(string.replace)

it can list of methods help

Dictionaries operation

NO COMMENTS