Question: a) What will be the output for each print statement of the code given below. list1=[1, 2, 3, 4, 7, 1, 9] list1.pop(1) print (list1)
a)
What will be the output for each print statement of the code given below.
list1=[1, 2, 3, 4, 7, 1, 9]
list1.pop(1)
print (list1)
list1.remove(1)
print (list1)
list1.clear()
print(list1)
del list1
print(list1)
4
b)
Declare a tuple with 8 elements having values from domain (0, 10). Convert it into a list and add two more elements in it, one at location 5th and another at the end using appropriate list methods. Now the list will have a total of 10 elements. Iterate through this list using the while and range function. When the particular list element is greater than 5, display its square, otherwise display the factorial of that list element.
4.
a)
What will be the output of the code given below?
val = 0
def function1():
print("Printing inside function1",val)
return
def function2(val):
print("Printing inside function2 first",val)
val = 20
print("Printing inside function2 Second",val)
return
function1()
print("Printing outside function1",val)
function2(val)
print("Printing outside function2",val)
Also mention the reasons behind your output in terms of scope and lifetime of a variable.
b)
Locate the positional, default and keyword arguments in the code given below:
def function1 (b, c, d, a=10):
print(a, b, c, d)
function1(10, 20, d=30)
Also, differentiate between positional, keyword and default function arguments in terms of their number and order.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
