Python Scripting - Week 8 Flashcards
What is the best way to pass multiple values to a function ?
The the best way is to use *args,
By using *args , you are able to pass values you want.
def add_em_up(*args):
sum=0
for i in args:
sum+=i
return sum
print(add_em_up(1,2,3,4,5,6,7,8,9,10))
print(add_em_up(1,2,3,4))
What *args returns to a function ?
IT returns a tuple ?
How to pass and list to *args ?
print(add_em_up(*[1,2,3,4]))
How tu use *args with other variables ?
def add_em_upUP(a,b,args):
print(a,b,args)
sum=0
for i in args:
sum+=i
return sum+a+b
print(add_em_upUP(2,2,[2,6,3,4,5]))
How to unpack iterable using an operator ?
print(*“Hello”)
H e l l o
a=[1,2,3,4]
print(*a)
1 2 3 4
Write a program to assign a list** [1,2,3,4,5,6,7,8 ,9,10 ]** to variables a,b,c
in the following way,
value at index 0 is assign to a
values at index 1 to 9 is assighnd to b
and value at intex 10 is assigned to c
a,*b,c=[1,2,3,4,5,6,7,8,9,10]
print(a)
1
print(b)
[2, 3, 4, 5, 6, 7, 8, 9]
print(c)
10
What is a Module in Python ?
Every Pythom file is an module ?
What is package ?
A group of python modules is a package
What is a Library ?
When something is “published “ we often call it a library ?