Python Fundamentals Entry Test

Section 1. Introduction to Python

1. What is the correct way to print "Hello, World!" in Python?






2. Which of these is a valid Python variable name?






3. What is the purpose of indentation in Python?






4. Which comment style is valid in Python?






5. Which of these is a correct way to run a Python script?






Section 2. Data Types

6. What is the output of this code?

text = "Python" print(text[1:4])





7. Which method converts string to uppercase?






8. What is the output?

nums = [1, 2, 3] print(nums * 2)





9. Which is correct format specifier for floating point with 2 decimals?






10. What does len([]) return?






Section 3. Program Flow

11. Which loop is correct in Python?






12. What does the break statement do?






13. Output of this code?

x = 3 if x == 3: print("Equal") else: print("Not Equal")





14. Which is correct use of match in Python?

value = "yes" match value: case "yes": print("Confirmed") case "no": print("Denied")





15. What is output?

for i in range(3): print(i, end=" ")





Section 4. Functions

16. What is the correct syntax of a Python function?






17. What does this code print?

def f(*args): return len(args) print(f(1,2,3))





18. What does this code print?

def greet(name="World"): print("Hello", name) greet()





19. Which function definition is correct for both positional and keyword args?






20. What is a lambda in Python?






Section 5. Introduction to OOP

21. Which is the correct class definition?






22. What is self in Python classes?






23. What does this code print?

class A: def __init__(self, x): self.x = x a = A(5) print(a.x)





24. Which method is used as constructor?






25. Which is correct inheritance syntax?






26. Which statement is correct about class variables?






27. What is method overriding?






28. Which is a static method?

class A: @staticmethod def f(): return 42





29. Which is correct example of class pattern matching?

class Point: def __init__(self, x, y): self.x, self.y = x, y p = Point(1, 2) match p: case Point(x, y): print(x, y)





30. Which is true about encapsulation in Python?