Python Scripting - Week 8 Flashcards

1
Q

What is the best way to pass multiple values to a function ?

A

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))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What *args returns to a function ?

A

IT returns a tuple ?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to pass and list to *args ?

A

print(add_em_up(*[1,2,3,4]))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How tu use *args with other variables ?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to unpack iterable using an operator ?

A

print(*“Hello”)
H e l l o

a=[1,2,3,4]
print(*a)
1 2 3 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Module in Python ?

A

Every Pythom file is an module ?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is package ?

A

A group of python modules is a package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Library ?

A

When something is “published “ we often call it a library ?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly