Python Practice – Questions & Answers
Beginner Level
Q31. Create a list.
nums = [1,2,3]
Q32. Access list element.
nums[0]
Q33. Create a tuple.
t = (1,2,3)
Q34. Create a dictionary.
user = {"name":"Vijay","age":25}Q35. If statement.
if age > 18:
print("Adult")
Intermediate Level
Q36. Try-except block.
try:
x=10/0
except:
print("Error")
Q37. Finally block.
Always executes.
Q38. File write.
f=open("a.txt","w")
f.write("Hi")
f.close()
Q39. File read.
f=open("a.txt","r")
print(f.read())
Q40. with statement.
with open("a.txt") as f:
print(f.read())
Advanced Level
Q41. Iterator.
Object with __iter__ and __next__.
Q42. Multi-threading.
Run tasks in parallel.
Q43. GIL.
Global Interpreter Lock.
Q44. Multiprocessing.
Uses multiple CPU cores.
Q45. Exception raising.
raise ValueError("Error")
No comments:
Post a Comment