Data Types in Python | list, tuple and range - Leela Soft Madhu Sir

Опубликовано: 05 Ноябрь 2024
на канале: Leela Soft
233
55

#LeelaSOFT #Madhu #BPKTECHTUTS
Sequence Types:
list
tuple
range

list Data Type:
1.Insertion order is preserved
2. Heterogeneous objects
3.Duplicates are allowed
4.Mutable (modifications are allowed)

Creation of a list object:
1.by using [] #empty list
2.by using [10, 20.8, "Java"]
3.by using list() #empty list
4.by using list(iterable_item)
5.by using list comprehension:
[x for x in iterable]

tuple Data Type:
1.Insertion order is preserved
2.Heterogeneous objects
3.Duplicates are allowed
4.Immutable (modifications are not allowed)

Creation of tuple:
1.by using () #empty tuple
2.by using (10,20,30)
3.by using tuple() #empty tuple
4.by using tuple(iterable_item)

Singleton tuple:
10, or (10,)

x = 10,
type(x)

Accessing:
by using index:

TypeError: 'tuple' object does not support item assignment

range Data Type:
1.Insertion order is preserved
2.Immutable (modifications are not allowed)

Creation of range:
1.range(stop)
2.range(start, stop)
3.range(start, stop, step)

1.range(stop)
x = range(5)

2.range(start, stop)
x = range(1,6)

3.range(start, stop, step)
x = range(1,11,1)

step:
1.by default step is 1 (+ve)
start is lessthan stop

2.if step is -ve
start is greaterthan stop

TypeError: 'range' object does not support item assignment