Computer Science, asked by lashikagarg8104, 5 months ago

5. Write a program in python to demonstrate packing and unpacking of values using tuples. 4

Answers

Answered by amalroy4847
0

Answer:

# A Python program to demonstrate need

# of packing and unpacking

# A sample function that takes 4 arguments

# and prints them.

def fun(a, b, c, d):

print(a, b, c, d)

# Driver Code

my_list = [1, 2, 3, 4]

# This doesn't work

fun(my_list)

Output :

TypeError: fun() takes exactly 4 arguments (1 given)

Answered by Anonymous
2

# Python code to study about

# unpacking python tuple using function

# function takes normal arguments

# and multiply them

def result(x, y):

return x * y

# function with normal variables

print (result(10, 100))

# A tuple is created

z = (10, 100)

# Tuple is passed

# function unpacked them

print (result(*z))

Output:

1000

1000

Plz Like it . Give me plz and follow me

Similar questions