collection data types in python

 

collection data types in python


there are list data types that are used to store multiple values:

1. list,

2. tuple,

3.set 

4.dict



datatype     ordered duplicates allowed or not changeable


list       yes    yes                    yes


set       no no                 no


tuple               yes yes                 no


dict       yes    no(keys)                yes



list

list is a sequence data types that are used to store multiple values.

while using a list where the data is as follows:

a. ordered
b. duplicates are allowed
c. changeable

syntax:
var_name=[value1,value2,...]


example:
names=["sam","max","alax"]
ages=[23,4,53,3]
data=["sam","delhi",23,11023,True]

there are several methods for list elements

tuple

tuple is a Sequence data type that are used to store multiple values.

while using a list where the data is as follows:

a. ordered
b. duplicates are allowed
c. unchangeable

syntax:
var_name=(value1,value2,...)


example:
names=("sam","max","alax")
ages=(23,4,53,3)
data=("sam","delhi",23,11023,True)





set

set is a Sequence data type that are used to store multiple values.

while using a list where the data is as follows:

a. unordered
b. duplicates are not allowed
c. unchangeable

syntax:
var_name={value1,value2,...}


example:
names={"sam","max","alax"}
ages={23,4,53,3}
data={"sam","delhi",23,11023,True}


dict

dict is a Sequence data type that are used to store multiple data in the form of key and value.

while using a list where the data is as follows:

a. ordered
b. duplicate keys are not allowed
c. changeable

syntax:
var_name={key1:value1,key2:value2,...}


example:
data={"name":"sam","age":29,"pincode":10023,"salary":20000}






0 Comments