1 What Will Be The Output of Following Code
1 What Will Be The Output of Following Code
1 What Will Be The Output of Following Code
Ans:
Ans:
Ans:
Ans:
Ans:
1|Page
7 Explain List Comprehension and Elegant way to create new List:
Ans:
1. List comprehension is an elegant and concise way to create new list from an
existing list in Python.
2. List comprehension consists of an expression followed by for statement inside
square brackets.
3. Here is an example to make a list with each item being increasing power of 2.
pow2 = []
for x in range(10):
pow2.append(2 ** x)
Ans:
print('p' in my_list)
print('a' in my_list)
Ans:
Ans:
2|Page