🐍 Ultimate Python Syntax Mastery Quiz
The Complete Test: Slicing, Iteration, Built-ins, OOP, and Advanced Features
📋 Quiz Overview
80 Questions
covering all Python fundamentals
8 Sections
: Core fundamentals to advanced features
Edge Cases
: Tests the limits of your knowledge
Real Syntax
: Every question based on actual Python behavior
0
of
80
questions answered
🔪 Slice Assignment Mastery
Question 1:
What is the result after this slice assignment?
lst = [1, 2, 3, 4, 5] lst[1:3] = ['a', 'b'] print(lst)
A) [1, 'a', 'b', 4, 5]
B) [1, 'a', 3, 'b', 5]
C) ['a', 'b', 3, 4, 5]
D) [1, 2, 'a', 'b', 5]
Question 2:
What happens when you shrink a list with slice assignment?
lst = [1, 2, 3, 4, 5] lst[1:4] = ['x'] print(lst)
A) [1, 'x', 5]
B) [1, 'x', 4, 5]
C) ['x', 4, 5]
D) ValueError
Question 3:
What is the result of step slice assignment?
lst = [10, 20, 30, 40, 50] lst[::2] = [1, 2, 3] print(lst)
A) [1, 20, 2, 40, 3]
B) [1, 2, 3, 40, 50]
C) [10, 1, 30, 2, 50, 3]
D) ValueError
Question 4:
What happens with mismatched step slice assignment?
lst = [1, 2, 3, 4, 5] lst[::2] = [10, 20] # 3 positions, 2 values
A) [10, 2, 20, 4, 0]
B) [10, 2, 20, 4, 5]
C) ValueError
D) [10, 20, 3, 4, 5]
Question 5:
What does negative step slice assignment do?
lst = ['a', 'b', 'c', 'd', 'e'] lst[::-2] = ['x', 'y', 'z'] print(lst)
A) ['z', 'b', 'y', 'd', 'x']
B) ['x', 'b', 'y', 'd', 'z']
C) ['a', 'x', 'c', 'y', 'z']
D) ValueError
🔄 Iteration & Loop Mastery
Question 6:
What does this range produce?
list(range(-5, 5, 2))
A) [-5, -3, -1, 1, 3]
B) [-5, -3, -1, 1, 3, 5]
C) [-3, -1, 1, 3]
D) [-5, -3, -1, 1]
Question 7:
What is the result of range with zero step?
list(range(5, 10, 0))
A) [5, 5, 5, 5, 5]
B) []
C) ValueError
D) [5, 6, 7, 8, 9]
Question 8:
What does enumerate with negative start produce?
list(enumerate(['a', 'b', 'c'], start=-1))
A) [(-1, 'a'), (0, 'b'), (1, 'c')]
B) [(0, 'a'), (1, 'b'), (2, 'c')]
C) ValueError
D) [('a', -1), ('b', 0), ('c', 1)]
Question 9:
What happens when zip has empty iterable?
list(zip([1, 2, 3], [], ['a', 'b']))
A) [(1, None, 'a'), (2, None, 'b')]
B) []
C) [(1, 'a'), (2, 'b'), (3, None)]
D) ValueError
Question 10:
What does this nested loop output?
result = [] for i in range(2): for j in range(3): if i == j: continue result.append((i, j)) print(result)
A) [(0, 1), (0, 2), (1, 0), (1, 2)]
B) [(0, 0), (1, 1)]
C) [(0, 1), (0, 2), (1, 0)]
D) [(1, 0), (1, 2)]
⚙️ Built-in Functions Mastery
Question 11:
Which call to int() is valid?
A) int("ff", 16)
B) int("1010", 2)
C) int("123", 10)
D) All of the above
Question 12:
What does round(2.675, 2) return?
A) 2.68
B) 2.67
C) 2.7
D) 3
Question 13:
What does pow(2, 3, 5) return?
A) 8
B) 3
C) 13
D) 40
Question 14:
What does divmod(17, 5) return?
A) 3.4
B) (3, 2)
C) [3, 2]
D) 2
Question 15:
What happens with max() on an empty list with default?
max([], default=42)
A) 42
B) ValueError
C) None
D) []
Question 16:
What does sum() with start parameter do?
sum([1, 2, 3], 10)
A) 6
B) 16
C) [1, 2, 3, 10]
D) TypeError
Question 17:
What does filter(None, [0, 1, 2, '', 'hello', False]) return?
A) [1, 2, 'hello']
B) [0, 1, 2, '', 'hello', False]
C) [1, 2, 'hello', True]
D) A filter object
Question 18:
What does sorted() with key parameter do?
sorted(['apple', 'pie', 'a'], key=len)
A) ['a', 'pie', 'apple']
B) ['apple', 'pie', 'a']
C) ['a', 'apple', 'pie']
D) [1, 3, 5]
Question 19:
What does chr(65) return?
A) 65
B) "65"
C) "A"
D) ValueError
Question 20:
What does bin(10) return?
A) 10
B) "1010"
C) "0b1010"
D) [1, 0, 1, 0]
📍 Indexing & Variable Assignment
Question 21:
What does negative indexing beyond list length return?
lst = [1, 2, 3] print(lst[-5])
A) 1
B) None
C) IndexError
D) 3
Question 22:
What are the values after this star assignment?
a, *b, c, d = [1, 2, 3, 4, 5, 6] print(b)
A) [2, 3, 4]
B) [2, 3, 4, 5]
C) [3, 4]
D) [2, 3]
Question 23:
What happens with multiple star expressions?
*a, *b = [1, 2, 3, 4]
A) a=[1,2], b=[3,4]
B) a=[1,2,3,4], b=[]
C) SyntaxError
D) a=[], b=[1,2,3,4]
Question 24:
What happens with this chained assignment?
a = b = [1, 2, 3] a.append(4) print(b)
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) [4]
D) NameError
Question 25:
What does slicing beyond bounds return?
lst = [1, 2, 3] print(lst[10:20])
A) []
B) IndexError
C) [None, None]
D) [1, 2, 3]
🏗️ Object-Oriented Programming
Question 26:
What is the output?
class A: def method(self): print("A") class B: def method(self): print("B") class C(A, B): pass C().method()
A) A
B) B
C) AB
D) TypeError
Question 27:
What happens with class variables?
class MyClass: class_var = [] a = MyClass() b = MyClass() a.class_var.append(1) print(len(b.class_var))
A) 0
B) 1
C) 2
D) AttributeError
Question 28:
What does super() do in inheritance?
class A: def __init__(self): self.value = 1 class B(A): def __init__(self): super().__init__() self.value = 2 b = B() print(b.value)
A) 1
B) 2
C) None
D) AttributeError
Question 29:
What does this property decorator do?
class Circle: def __init__(self, radius): self._radius = radius @property def area(self): return 3.14 * self._radius ** 2 c = Circle(2) print(c.area)
A) 12.56
B) A method object
C) TypeError
D) 4
Question 30:
What is the output with __str__ method?
class Point: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return f"Point({self.x}, {self.y})" p = Point(1, 2) print(p)
A) Point(1, 2)
B) <__main__.Point object at 0x...>
C) (1, 2)
D) 1, 2
🚀 Advanced Features
Question 31:
What does this generator do?
def gen(): yield 1 yield 2 yield 3 g = gen() print(next(g)) print(list(g))
A) 1\n[1, 2, 3]
B) 1\n[2, 3]
C) 1\n[]
D) StopIteration
Question 32:
What does this context manager do?
class Context: def __enter__(self): print("Enter") return self def __exit__(self, exc_type, exc_val, exc_tb): print("Exit") return True with Context() as c: raise ValueError("Error") print("After error") print("After context")
A) Enter\nExit\nAfter context
B) Enter\nAfter error\nExit\nAfter context
C) Enter\nValueError
D) Enter\nExit
Question 33:
What does this decorator do?
def decorator(func): def wrapper(): print("Before") result = func() print("After") return result return wrapper @decorator def test(): print("Test") return "Done" test()
A) Before\nTest\nAfter
B) Test
C) Before\nAfter
D) Done
Question 34:
What does this comprehension with condition produce?
result = [x if x > 0 else 0 for x in range(-3, 4)] print(result)
A) [0, 0, 0, 0, 1, 2, 3]
B) [1, 2, 3]
C) [-3, -2, -1, 0, 1, 2, 3]
D) [0, 0, 0, 1, 2, 3]
Question 35:
What does this lambda function do?
func = lambda x=10, y=20: x + y print(func(y=5))
A) 15
B) 25
C) 30
D) TypeError
⚠️ Error Handling
Question 36:
What is the result?
try: result = 10 / 0 except ZeroDivisionError: result = "error" else: result = "success" finally: result = "done" print(result)
A) "error"
B) "success"
C) "done"
D) ZeroDivisionError
Question 37:
What does this try-finally do?
def func(): try: return "try" finally: return "finally" print(func())
A) "try"
B) "finally"
C) "try finally"
D) None
Question 38:
What happens with multiple exception types?
try: x = int("hello") except (ValueError, TypeError) as e: print(type(e).__name__)
A) ValueError
B) TypeError
C) Exception
D) tuple
Question 39:
What does exception chaining do?
try: try: 1 / 0 except ZeroDivisionError as e: raise ValueError("New error") from e except ValueError as e: print(e.__cause__.__class__.__name__)
A) ValueError
B) ZeroDivisionError
C) Exception
D) None
Question 40:
What does this for-else loop do?
for i in range(3): if i == 5: break else: print("Completed") print("Done")
A) Completed\nDone
B) Done
C) Completed
D) Nothing is printed
💥 Extreme Edge Cases
Question 41:
What does range with float arguments do?
list(range(1.5, 5.5))
A) [1.5, 2.5, 3.5, 4.5]
B) [2, 3, 4, 5]
C) TypeError
D) [1, 2, 3, 4, 5]
Question 42:
What does this walrus operator do?
if (n := len([1, 2, 3])) > 2: print(n)
A) 3
B) True
C) SyntaxError
D) Nothing is printed
Question 43:
What does dictionary union operator do?
{'a': 1, 'b': 2} | {'b': 3, 'c': 4}
A) {'a': 1, 'b': 2, 'c': 4}
B) {'a': 1, 'b': 3, 'c': 4}
C) {'b': 2, 'b': 3}
D) TypeError
Question 44:
What does floating point precision issue show?
print(0.1 + 0.2 == 0.3)
A) True
B) False
C) 0.3
D) TypeError
Question 45:
What does this complex slice deletion do?
lst = [1, 2, 3, 4, 5, 6] del lst[::2] print(lst)
A) [2, 4, 6]
B) [1, 3, 5]
C) []
D) [1, 2, 3, 4, 5, 6]
🎯 Comprehensive Mixed Challenges
Question 46:
What does this advanced unpacking do?
def func(*args, **kwargs): return len(args) + len(kwargs) result = func(*[1, 2], **{'a': 3, 'b': 4}) print(result)
A) 2
B) 4
C) 6
D) TypeError
Question 47:
What does this complex slicing produce?
s = "abcdefgh" print(s[1:7:2])
A) "bdf"
B) "bdfh"
C) "bdg"
D) "ace"
Question 48:
What does mutable default argument do?
def func(lst=[]): lst.append(1) return lst print(len(func()) + len(func()))
A) 1
B) 2
C) 3
D) 4
Question 49:
What does this nested comprehension produce?
result = [x + y for x in [1, 2] for y in [10, 20]] print(result)
A) [11, 21, 12, 22]
B) [11, 12, 21, 22]
C) [30, 40]
D) [3, 4, 30, 40]
Question 50:
What does this generator send() method do?
def gen(): x = yield yield x * 2 g = gen() next(g) result = g.send(5) print(result)
A) 5
B) 10
C) None
D) StopIteration
Question 51:
What does metaclass do to class creation?
class Meta(type): def __new__(mcs, name, bases, attrs): attrs['class_id'] = name.upper() return super().__new__(mcs, name, bases, attrs) class Test(metaclass=Meta): pass print(Test.class_id)
A) "Test"
B) "TEST"
C) "test"
D) AttributeError
Question 52:
What does this setattr() function do?
class Obj: pass obj = Obj() setattr(obj, 'dynamic_attr', 42) print(hasattr(obj, 'dynamic_attr'))
A) True
B) False
C) 42
D) AttributeError
Question 53:
What does this complex f-string formatting do?
name = "Python" width = 10 print(f"{name:^{width}}")
A) " Python "
B) "Python "
C) " Python"
D) SyntaxError
Question 54:
What does this any() and all() combination do?
data = [[], [1], [2, 3]] result = any(all(x > 0 for x in sublist) for sublist in data if sublist) print(result)
A) True
B) False
C) None
D) TypeError
Question 55:
What does this operator precedence produce?
result = 2 + 3 * 4 ** 2 // 5 print(result)
A) 11
B) 8
C) 20
D) 80
Question 56:
What does this complex assignment pattern do?
a, b = 10, 20 a, b = b, a + b print(a, b)
A) 20 30
B) 20 10
C) 30 20
D) 10 30
Question 57:
What does this zip with unpacking do?
list(zip(*[(1, 'a'), (2, 'b'), (3, 'c')]))
A) [(1, 2, 3), ('a', 'b', 'c')]
B) [(1, 'a'), (2, 'b'), (3, 'c')]
C) [1, 2, 3, 'a', 'b', 'c']
D) TypeError
Question 58:
What does this reversed() on range produce?
list(reversed(range(5)))
A) [4, 3, 2, 1, 0]
B) [0, 1, 2, 3, 4]
C) TypeError
D) [5, 4, 3, 2, 1]
Question 59:
What does this print() with custom parameters do?
print("A", "B", "C", sep="-", end="...\n")
A) A-B-C...
B) A B C
C) A-B-C
D) ABC...
Question 60:
What does this complex slice with None produce?
lst = [1, 2, 3, 4, 5] print(lst[None:None:None])
A) [1, 2, 3, 4, 5]
B) []
C) [None, None, None]
D) TypeError
Question 61:
What does this global vs nonlocal do?
x = 100 def outer(): x = 10 def inner(): global x x = 20 inner() return x print(outer(), x)
A) 10 20
B) 20 20
C) 20 100
D) 10 100
Question 62:
What does this slice object produce?
s = slice(1, 5, 2) lst = [0, 1, 2, 3, 4, 5, 6] print(lst[s])
A) [1, 3]
B) [1, 2, 3, 4]
C) [1, 3, 5]
D) slice(1, 5, 2)
Question 63:
What does this type() vs isinstance() show?
class A: pass class B(A): pass b = B() print(type(b) == A, isinstance(b, A))
A) False True
B) True False
C) True True
D) False False
Question 64:
What does this string center() method do?
"hello".center(10, '-')
A) "--hello---"
B) "---hello--"
C) "hello-----"
D) "-----hello"
Question 65:
What does this eval() function do?
x = 5 result = eval("x * 2 + 3") print(result)
A) 13
B) "x * 2 + 3"
C) NameError
D) SyntaxError
Question 66:
What does this vars() function return?
class Test: def __init__(self): self.a = 1 self.b = 2 t = Test() print(len(vars(t)))
A) 1
B) 2
C) 3
D) TypeError
Question 67:
What does this dir() function show?
print('__add__' in dir(int))
A) True
B) False
C) '__add__'
D) TypeError
Question 68:
What does this id() function compare?
a = [1, 2, 3] b = a c = a.copy() print(id(a) == id(b), id(a) == id(c))
A) True False
B) False True
C) True True
D) False False
Question 69:
What does this frozenset difference show?
s1 = frozenset([1, 2, 3]) s2 = frozenset([2, 3, 4]) print(sorted(s1 - s2))
A) [1]
B) [4]
C) [1, 4]
D) [2, 3]
Question 70:
What does this callable() function test?
print(callable(print), callable(42), callable(lambda x: x))
A) True False True
B) True True False
C) False False True
D) True True True
Question 71:
What does this hash() function show?
print(hash((1, 2)) == hash((1, 2)))
A) True
B) False
C) TypeError
D) None
Question 72:
What does this memoryview() object do?
data = b"hello" mv = memoryview(data) print(mv[1])
A) 101
B) 'e'
C) b'e'
D) TypeError
Question 73:
What does this oct() function return?
print(oct(64))
A) "64"
B) "0o100"
C) "100"
D) 100
Question 74:
What does this ord() function return?
print(ord('A') - ord('a'))
A) -32
B) 32
C) 0
D) 1
Question 75:
What does this repr() vs str() show?
text = "hello\nworld" print(len(str(text)), len(repr(text)))
A) 11 13
B) 11 11
C) 13 11
D) 13 13
Question 76:
What does this complex slice assignment with overlapping ranges do?
lst = [1, 2, 3, 4, 5] lst[1:4] = lst[2:5] print(lst)
A) [1, 3, 4, 5]
B) [1, 3, 4, 5, 5]
C) [1, 2, 3, 4]
D) [3, 4, 5, 4, 5]
Question 77:
What does this format() function with complex formatting do?
print(format(42, '08b'))
A) "00101010"
B) "101010"
C) "42"
D) "0b101010"
Question 78:
What does this zip with single argument produce?
list(zip([1, 2, 3]))
A) [(1,), (2,), (3,)]
B) [1, 2, 3]
C) [(1, 2, 3)]
D) TypeError
Question 79:
What does this enumerate on empty iterable produce?
list(enumerate([]))
A) []
B) [(0, None)]
C) [0]
D) StopIteration
Question 80:
🎯 FINAL CHALLENGE: What does this ultimate Python syntax combination produce?
result = [ x * y for x in range(3) for y in range(x, 3) if (x + y) % 2 == 0 ] print(sum(result))
A) 6
B) 10
C) 8
D) 4
Submit Ultimate Quiz
0%
You scored 0 out of 80 questions correctly!
0%
Try Again