Python Collection Part - 4 [Range,Set,FrozenSet]
For Professionals and Freshers |
range datatype represents a sequence of values, range datatype is immutable. We can use range in various ways /forms
form1 : range (10) : it represents value from 0 to 9
form2: range(10,50): it represents from 10 to 49
form3: range(10,50,5): it represents 10 to 49 step of 5
range only applicable on integer not on float values.
Set:
If you want to represent a group of object as a single entity where duplication not allowed and insertion order not preserved then we should go for set
{} - Set can be represented by using curly barcket
s[1:] - indexing order sequencing not applicable on set
s=set() // way to create empty set
for i in range(10)
s.add(i)
Example2:
s={'govind','ravi','shiva'}
FrozenSet:
Frozenset is immutable we cant change once created.only one diffrence between set and frozenset is
frozen set is immutable where as set is mmutable
s={10,20,30,40}
fs=frozenset(s)
type(fs)
Comments
Post a Comment