Q1: What will be output of: >>> s = 'malayalam' >>> s.strip('mal') Q2: Which of these are valid variable names? a. &code = 'abc' b. discount% = 90 c. _ = "Alpha" d. string = "Beta" Q3: What will be the output of: >>> s = " Python Program " >>> s.lstrip("P") Q4: What will be the output of: >>> l = ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon'] >>> l[-2][2] Q5: What will be the output of: var = 0 if var: print("In If") elif (var == 0): print("In Elif 1") elif (var == 0): print("In Elif 2") else: print("In Else") Q6: What will be the output of: for i in range(10): if(i == 5): break else: print(i, sep = " ") else: print("In Else 2") Q7: What will be output of: for x in range(6): print(x) else: print("Finally finished!") Q8: A riddle. >>> t = (1, 2, [30, 40]) >>> t[2] += [50, 60] What happens next? Choose the best answer: a) t becomes (1, 2, [30, 40, 50, 60]). b) TypeError is raised with the message 'tuple' object does not support item assignment. c) Neither. d) Both a and b. Q9: What of these gives you back a dict: a) a = dict(one=1, two=2, three=3) b) b = {'one': 1, 'two': 2, 'three': 3} c) c = dict(zip(['one', 'two', 'three'], [1, 2, 3])) d) d = dict([('two', 2), ('one', 1), ('three', 3)]) e) e = dict({'three': 3, 'one': 1, 'two': 2}) Q10: What is the output of: i = 01 print(i + 5) Q11: What is the output of: import re s = "Malaaavikaa" s = re.sub("a{2}", "*", s) print(s) Q12: What is the output of: class Person(): def __init__(self, pid): self.pid = pid obama = Person(100) obama.age = 49 print(obama.age + 2) Q13: l = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'] Sort this list based on string length in one line.
Sunday, May 28, 2023
Python Quiz (13 Questions, May 2023)
Labels:
Python,
Technology
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment