Python is a high-level, interpreted programming language designed to be easy to learn and use. Its syntax is simple and readable, making it popular among beginners and experienced developers alike.
Answer the following questions:-
1. Which Python function is used to get user input?
a) input()
b) print()
c) scan()
d) read()
2. What will happen if you divide a number by zero in Python? a) It will return infinity. b) It will throw a ZeroDivisionError. c) It will return 0. d) It will return NaN.
3. Which arithmetic operation is used to add two numbers? a) / b) * c) + d) -
4. How would you handle division by zero in Python? a) Use an if statement to check if the denominator is zero. b) Skip the division and continue. c) Use a try-except block. d) Both a and c.
5. Which of the following is the correct syntax to perform multiplication in Python? a) 5 * 3 b) 5 x 3 c) 5 # 3 d) 5 @ 3
6.What is the first step to count vowels in a string? a) Use a for loop to iterate through the string. b) Convert the string to uppercase. c) Split the string into words. d) Reverse the string.
7. Which of the following characters are considered vowels in English? a) a, e, i, o, u b) a, b, c, d, e c) 1, 2, 3, 4, 5 d) q, r, t, y, u
8. Which Python operator would you use to check if a character is a vowel? a) in b) == c) != d) and
9. Which of these methods would be used to split a string into characters? a) split() b) list() c) join() d) strip()
10. How would you count the vowels in the string "hello world"? a) sum(1 for char in 'hello world' if char in 'aeiou') b) count('aeiou', 'hello world') c) len('aeiou') d) vowelCount('hello world')
11. Which of these is a valid Python method to remove spaces from a string? a) split() b) replace() c) strip() d) remove()
12. How can you check if a string is a palindrome? a) Reverse the string and compare it with the original string. b) Reverse the string and check for vowels. c) Check if the string starts with a vowel. d) Convert the string to lowercase only.
13. Which function can you use to convert a string to lowercase in Python? a) lower() b) toLower() c) str() d) case()
14. What should be done before checking for a palindrome? a) Remove spaces and convert the string to lowercase. b) Reverse the string and convert to uppercase. c) Replace all characters with numbers. d) Split the string into characters.
15. Which of the following phrases is a palindrome? a) "madam" b) "hello world" c) "python" d) "example"
16. Which Python function is used to find the largest number in a list? a) max() b) min() c) sort() d) largest()
17. What will max([1, 2, 3, 4]) return? a) 1 b) 2 c) 3 d) 4
18. Which of these is a valid list in Python? a) [1, 2, 3] b) {1, 2, 3} c) (1, 2, 3) d) max(1, 2, 3)
19. Which function will give the smallest number in a list? a) max() b) min() c) first() d) lowest()
20. If numbers = [10, 20, 15, 30], what will max(numbers) return? a) 15 b) 10 c) 30 d) 20
21. Which of the following is the correct formula for generating a Fibonacci sequence? a) Each number is the sum of the previous two numbers. b) Each number is multiplied by the previous one. c) Each number is the difference of the previous two numbers. d) Each number is squared.
22. Which Python construct would be used to generate the Fibonacci sequence? a) for loop b) while loop c) if-else d) try-except
23. What will the Fibonacci sequence up to 10 look like? a) [1, 1, 2, 3, 5, 8, 13] b) [0, 1, 2, 3, 5, 8, 13] c) [1, 2, 3, 5, 8, 13, 21] d) [0, 1, 1, 2, 3, 5, 8]
24. How do you generate the next number in the Fibonacci sequence using a loop? a) Add the last two numbers together. b) Subtract the last two numbers. c) Multiply the two numbers. d) Find the difference.
25. What is the 6th Fibonacci number? a) 5 b) 8 c) 13 d) 21
26. Which Python method would you use to split a string into words? a) split() b) join() c) strip() d) replace()
27. What is the output of "hello world".split()? a) ['hello', 'world'] b) 'hello world' c) ['hello world'] d) ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']
28. How can you count the number of words in the string "Python is awesome"? a) len("Python is awesome".split()) b) split("Python is awesome") c) count("Python is awesome") d) word_count("Python is awesome")
29. What is the purpose of the split() method? a) To join words together. b) To remove spaces from a string. c) To separate a string into words or characters. d) To convert a string to uppercase.
30. Which of the following will return the word count of the sentence "The quick brown fox jumps"? a) len("The quick brown fox jumps".split()) b) count("The quick brown fox jumps") c) word_count("The quick brown fox jumps") d) split("The quick brown fox jumps")
31. Which of the following is a valid way to check if a string is a palindrome? a) s == s[::-1] b) s.reverse() == s c) reverse(s) == s d) s == s[::-0]
32. In Python, what is the result of 5 / 0? a) ZeroDivisionError b) Infinity c) NaN d) 0
33. What is the default behavior of max() when called with an empty list? a) Return 0 b) Return None c) Throw an error d) Return the first element
34. Which of these is a valid Python data structure for storing multiple values? a) List b) String c) Tuple d) All of the above
35. How do you generate Fibonacci numbers in a loop in Python? a) Use two variables to store the previous two numbers and sum them. b) Use recursion. c) Use a list comprehension. d) All of the above.
36. Which is the correct way to check if an element is in a list in Python? a) if element in list: b) if list.contains(element): c) if element in list[]: d) if list.has(element):
37. What does input() return in Python? a) A string b) An integer c) A float d) A list
38. Which loop is best for iterating over each character in a string? a) for b) while c) foreach d) do-while
39. What is the output of the expression 'aeiou'.count('o')? a) 1 b) 0 c) 5 d) Error
40. What is the correct way to check for an empty string in Python? a) if not s: b) if s == '': c) if len(s) == 0: d) All of the above.
41. How do you handle exceptions in Python when performing division? a) Use try-except block b) Use if to check division c) Ignore the exception d) Print an error message
42. Which of these methods will convert a string to uppercase? a) upper() b) toUpper() c) capitalize() d) title()
43. Which data type is used to store a sequence of characters in Python? a) Integer b) List c) String d) Tuple
44. Which of these will correctly reverse a list in Python? a) list.reverse() b) list[::-1] c) reversed(list) d) All of the above
45. In which scenario would you use the continue statement? a) To skip the rest of the current loop iteration and move to the next one. b) To exit the loop completely. c) To stop the program. d) To pause the program.
46. How would you check if a string contains only alphabetic characters? a) s.isalpha() b) s.isdigit() c) s.isalnum() d) s.isnumeric()
47. Which method is used to add an element at the end of a list? a) append() b) insert() c) extend() d) push()
48. What does the len() function return when applied to a string? a) The number of characters in the string b) The number of words in the string c) The ASCII value of the string d) The string itself
49. What does str.split() do? a) It divides a string into a list of words. b) It splits a string into its individual characters. c) It returns the middle character of a string. d) It joins a string together.
50. What is the output of "123".isdigit()? a) True b) False c) 1 d) Error
51. Which of the following is used to add a comment in Python? a) # b) // c) /* d)
52. What will the statement list = [1, 2, 3]; list[1] = 5 do? a) It will change the second element of the list to 5. b) It will throw an IndexError. c) It will append 5 to the list. d) It will create a new list.
53. How do you remove an element from a list by value? a) list.remove(value) b) list.pop(value) c) del list[value] d) list.delete(value)
54. What is the result of [1, 2] + [3, 4]? a) [1, 2, 3, 4] b) [1, 2, [3, 4]] c) [1, 2] d) Error
55. Which of the following is used to check if a list is empty in Python? a) if not list: b) if list == []: c) if len(list) == 0: d) All of the above
56. What will happen if you try to access an index that is out of range in Python? a) IndexError b) ValueError c) KeyError d) TypeError
57. What does the str method .replace() do? a) Replaces a substring with another substring in a string. b) Removes a substring from a string. c) Reverses the string. d) Changes the string to lowercase.
58. What is the result of "abc".replace('a', 'z')? a) "zbc" b) "abc" c) "a" d) Error
59. Which of these would correctly check if a string is numeric? a) isdigit() b) isnumeric() c) isalnum() d) Both a and b
60. What will "hello".upper() return? a) "HELLO" b) "hello" c) "Hello" d) Error