Python IntermediateadminNovember 21, 2026Uncategorized 1. Which value represents the Boolean false value in Python? FALSE FALSE Python Boolean literals are case-sensitive. 2. Which keyword begins a conditional statement in Python? if if A condition is followed by a colon and an indented block. 3. Which keyword provides an alternative branch when an if condition is false? elseif else It is used as the fallback branch of an if statement. 4. Which operator checks whether two values are equal? #NAME? #NAME? One equals sign assigns; the comparison operator uses two. 5. Which keyword checks another condition after an if condition? elif elif Python uses a shortened form of ‘else if’. 6. Which data structure stores unique elements? tuple set Adding an already-present element does not create a duplicate in this collection. 7. Which of the following is a valid variable name in Python? total_marks total_marks Variable names cannot start with a digit or contain hyphens, and keywords are reserved. 8. Which brackets are used to create a list in Python? { } [ ] A list literal uses square brackets. 9. Which statement is used to display output in Python? display() print() It is commonly used to show text and values on the screen. 10. Which operator is used for exponentiation in Python? ** ** It raises the left operand to the power of the right operand. 11. Which list method removes and returns the last item by default? remove() pop() With no index argument, this method operates on the final item. 12. Which keyword is used to define a class in Python? class class A class definition starts with this keyword followed by the class name. 13. What values are produced by range(3)? 0, 1, 2 0, 1, 2 The stop value is excluded and the default start is zero. 14. Which keyword sends a value back from a function? return return The caller receives the expression’s value. 15. Which block is used to handle an exception in Python? except except It follows a try block and handles matching exceptions. 16. Which symbol is used to write a single-line comment in Python? # # A comment marker is placed at the beginning of the line. 17. What is printed by: if 4 > 2: print(‘Yes’)? Yes Yes The condition evaluates to true, so the indented statement runs. 18. Which symbol creates an empty set in Python? [] set() Empty curly braces create a dictionary, not this collection. 19. What is the result of ‘Py’ + ‘thon’? Python Python The plus operator joins strings together. 20. Which list method adds one item to the end of a list? append() append() This method adds a single object after the current last element. 21. What is the result of 10 // 3 in Python? 3 3 This operator performs floor division and returns the quotient rounded down. 22. Which keyword immediately exits the nearest loop? exit break It terminates the loop rather than skipping just one iteration. 23. What is the result of calling len([4, 5, 6])? 3 3 The function counts the number of items in the list. 24. Which dictionary method returns a value for a key without raising KeyError when the key is missing (unless configured otherwise)? get() get() This method can also accept a default value as its second argument. 25. What is the result of 7 % 2? 1 1 The modulo operator returns the remainder after division. 26. Which operator checks whether a value belongs to a sequence or collection? in in It is often used in expressions such as ‘x in my_list’. 27. Which keyword is used to start code that may raise an exception? try try The potentially risky statements are placed inside this block. 28. What is the result of type(3.14) in Python? float float A numeric value containing a decimal point is represented using this type. 29. Which keyword starts a for loop in Python? loop for It is commonly used to iterate over items in a sequence. 30. What is the usual name of the first instance parameter in an instance method? self self This conventional parameter refers to the current instance. 31. Which built-in function returns the data type of an object? kind() type() Pass a value or variable to this function to inspect its type. 32. Which of these is a valid way to start the Python interactive interpreter command on many systems? startpy python This is the usual command when Python is on the system PATH. 33. Which file extension is commonly used for Python source files? .py .py Python scripts conventionally use a two-letter extension. 34. Which keyword skips the rest of the current loop iteration and moves to the next one? continue continue It does not end the entire loop. 35. Who created the Python programming language? James Gosling Guido van Rossum He began developing Python in the late 1980s. 36. In Python, what is the index of the first character in a string? -1 0 Python sequences use zero-based indexing. 37. What is a parameter in a function definition? A variable listed in the function definition A variable listed in the function definition It is the named input variable specified in the function header. 38. What is the output of len(‘Python’)? 6 6 Count each character in the word, including no extra spaces. 39. What is the result of [10, 20, 30][1]? 20 20 Remember that list indexing starts at zero. 40. Which loop continues while its condition remains true? while while The condition is checked before each iteration. 41. What is the data type of the value 25 in Python? float int This value is a whole number without a decimal point. 42. What is the result of not (5 > 2) ? FALSE FALSE First evaluate the comparison, then apply logical NOT. 43. Which method converts a string to uppercase? uppercase() upper() Call this method on a string to return an uppercase version. 44. Which brackets are commonly used to create a dictionary literal? ( ) { } A dictionary stores key-value pairs using this brace syntax. 45. Which keyword is used to create an anonymous function in Python? 匿名 lambda It introduces a small function expression. 46. Which statement about tuples is correct? Tuples can only store numbers Tuples are immutable After a tuple is created, its elements cannot be reassigned. 47. Which keyword is used to define a function in Python? fun def A function definition begins with this keyword followed by its name. 48. How do you access the value associated with key ‘name’ in dictionary d? d(‘name’) d[‘name’] Use the key inside square brackets after the dictionary variable. 49. Which string method removes whitespace from both ends of a string? trim() strip() This method returns a string with leading and trailing whitespace removed. 50. Which keyword is used to run cleanup code whether an exception occurs or not? finally finally This block is commonly used for cleanup operations. Loading … Question 1 of 50