Python tuple packing and unpacking - Python coding


Python tuple packing and unpacking

python tuple can also be created without using a tuple() class or enclosing the

items inside the parentheses. it is called the variable packing

#python tuple packing into tuple

tuple=23,44,66,'django'

print(tuple)

print(type(tuple))

#unpacking tuple into variable

a,b,c,d=tuple

print("a is =",a)

print("b is =",b)

print("c is =",c)

print("d is =",d)

print(type(a))

print(type(b))

print(type(c))

print(type(d))

output : 

(23, 44, 66, 'django')

<class 'tuple'>

a is = 23

b is = 44

c is = 66

d is = django

<class 'int'>

<class 'int'>

<class 'int'>

<class 'str'>


No comments:

Post a Comment

Latest Post

How to Generate Barcode and QR code For Our Products

 మీ products కి barcode / QR code generate చేయాలంటే OPTION 1: ONLINE (No Coding – Quick) Best for small shops / beginners 👉Free websites: T...