0% found this document useful (0 votes)
10 views17 pages

? Part 1 - Python Basics (Questions 1-25)

Uploaded by

Murtaza Karimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views17 pages

? Part 1 - Python Basics (Questions 1-25)

Uploaded by

Murtaza Karimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

📘 Part 1: Python Basics (Questions 1–25)

1. What symbol is used to start a comment in Python?


a) //
b) #
c) <!--
d) **

2. Which function prints output to the screen?


a) input()
b) print()
c) output()
d) echo()

3. What is the correct way to assign the value 5 to a variable x?


a) x == 5
b) x = 5
c) 5 = x
d) x := 5

4. How do you create a string literal?


a) 5
b) "Hello"
c) True
d) [1,2,3]

5. What is the result of 3 + 4 * 2?


a) 14
b) 11
c) 10
d) 7

6. How do you get user input?


a) input()
b) print()
c) scanf()
d) read()

7. Which of these is a valid variable name?


a) 1var
b) var_1
c) var-1
d) var 1

8. What data type is the value True?


a) String
b) Integer
c) Boolean
d) Float

9. What operator is used for exponentiation?


a) ^
b) **
c) //
d) %

10. How do you make a new line in a string?


a) \n
b) \t
c) \
d) \r

11. What will print(2 == 2) output?


a) True
b) false
c) 1
d) 2

12. Which keyword is used to define a function?


a) func
b) define
c) def
d) function

13. How do you start a block of code inside a function?


a) Indentation
b) Braces {}
c) Parentheses ()
d) Semicolon ;

14. What will print("Hello" + "World") output?


a) Hello World
b) HelloWorld
c) Hello+World
d) Hello+ World

15. What does the input() function return?


a) String
b) Integer
c) Boolean
d) Float

16. How do you convert a string '5' to an integer?


a) int('5')
b) str('5')
c) float('5')
d) convert('5')

17. What does the // operator do?


a) Division with remainder
b) Integer division
c) Exponentiation
d) Modulus

18. What is the output of print(10 % 3)?


a) 3
b) 1
c) 0
d) 10

19. How do you check if two values are equal?


a) =
b) ==
c) !=
d) :=

20. What will the following code print?


if 5 > 2:
print("Yes")

a) Yes
b) No
c) 5
d) Error
21. How do you write a single-line comment?
a) # Comment
b) // Comment
c)
d) /* Comment */

22. Which of these is NOT a Python keyword?


a) and
b) var
c) if
d) else

23. What does the function range(5) generate?


a) [1,2,3,4,5]
b) [0,1,2,3,4]
c) [0,1,2,3,4,5]
d) [5]

24. What will this code print?


print(type(3.14))

a) <class 'int'>
b) <class 'float'>
c) <class 'str'>
d) <class 'bool'>

25. What does print(len("Hello")) output?


a) 4
b) 5
c) 6
d) 7

26. Which of these is the correct way to write an if statement in Python?


a) if x > 5 then:
b) if x > 5:
c) if (x > 5)
d) if x > 5

27. What will this code print?


x = 10
print(x > 5 and x < 15)

a) False
b) True
c) Error
d) None

28. How do you create a list in Python?


a) {1, 2, 3}
b) [1, 2, 3]
c) (1, 2, 3)
d) <1, 2, 3>

29. How do you access the first element of a list myList?


a) myList[0]
b) myList[1]
c) myList.first()
d) myList(0)

30. What is the output of print(len([1, 2, 3, 4]))?


a) 3
b) 4
c) 5
d) Error

31. How do you append an element 5 to a list myList?


a) myList.add(5)
b) myList.append(5)
c) myList.push(5)
d) myList.insert(5)

32. Which keyword is used to create a loop that iterates over a sequence?
a) while
b) for
c) loop
d) iterate

33. What does this code print?


for i in range(3):
print(i)
a) 1 2 3
b) 0 1 2
c) 0 1 2 3
d) 3 2 1

34. What does the break statement do inside a loop?


a) Continues to the next iteration
b) Exits the loop
c) Pauses the loop
d) Skips the current iteration

35. How do you write a function that takes no arguments?


a) def myFunc:
b) def myFunc()
c) def myFunc():
d) function myFunc():

36. What will this function return?


def add(x, y):
return x + y
print(add(2, 3))

a) 5
b) 23
c) None
d) Error

37. How do you import a module named math?


a) import math
b) include math
c) using math
d) require math

38. Which symbol is used for the modulus operator?


a) %
b) //
c) **
d) /

39. What does bool(0) evaluate to?


a) True
b) False
c) None
d) Error

40. How do you write a multi-line comment?


a) ''' Comment '''
b) // Comment
c) /* Comment */
d) # Comment

41. How do you create a dictionary in Python?


a) {}
b) []
c) ()
d) <>

42. How do you add a key-value pair "name": "Alice" to a dictionary d?


a) d.add("name", "Alice")
b) d["name"] = "Alice"
c) d.append("name", "Alice")
d) d.insert("name", "Alice")

43. What will this code print?


d = {"a": 1, "b": 2}
print(d["b"])

a) 1
b) 2
c) b
d) Error

44. Which function converts a number to a string?


a) str()
b) int()
c) float()
d) convert()

45. What is the output of print(type([]))?


a) <class 'list'>
b) <class 'dict'>
c) <class 'tuple'>
d) <class 'set'>
46. What is the boolean value of an empty list?
a) True
b) False
c) None
d) Error

47. How do you check if a key "name" is in dictionary d?


a) "name" in d
b) d.has_key("name")
c) d.contains("name")
d) d["name"]

48. What does this code do?


for key in d:
print(key)

a) Prints all keys in dictionary d


b) Prints all values in dictionary d
c) Prints nothing
d) Error

49. What does the continue statement do?


a) Exits the loop
b) Skips the current iteration and continues with next
c) Restarts the loop
d) Pauses the loop

50. How do you write a conditional statement with multiple branches?


a) if … elif … else
b) if … else if … else
c) if … then … else
d) switch … case

51. What is the output of print(2 != 3)?


a) True
b) False
c) 0
d) 1

52. How do you start a while loop?


a) while x > 0
b) while (x > 0):
c) while x > 0:
d) loop while x > 0

53. What does this code print?


x=0

while x < 3:

print(x)

x += 1

a) 1 2 3
b) 0 1 2
c) 0 1 2 3
d) 1 2

54. What is the output of print(5 // 2)?


a) 2
b) 2.5
c) 3
d) 3.0

55. What is the data type of [1, 2, 3]?


a) tuple
b) list
c) dict
d) set

56. What does this code print?


print("Hello", end=" World")

a) Hello World
b) Hello
World
c) Hello
d) World

57. Which operator is used to check if two variables refer to the same
object?
a) ==
b) is
c) equals
d) :=

58. What is the result of bool("")?


a) True
b) False
c) None
d) Error

59. What does type({}) return?


a) <class 'dict'>
b) <class 'list'>
c) <class 'set'>
d) <class 'tuple'>

60. How do you declare a tuple with one element 5?


a) (5)
b) (5,)
c) [5]
d) {5}

61. Which function reads a line of input from the user?


a) input()
b) read()
c) get()
d) scanf()

62. What does int("5") + 3 evaluate to?


a) 8
b) 53
c) Error
d) 35

63. What does print(3 * "abc") output?


a) abcabcabc
b) abc3
c) Error
d) abc abc abc

64. Which of these is immutable?


a) list
b) dict
c) tuple
d) set

65. What does not True evaluate to?


a) True
b) False
c) None
d) Error

66. How do you get the length of a string s?


a) size(s)
b) length(s)
c) len(s)
d) count(s)

67. Which operator checks for inequality?


a) =!
b) !=
c) <>
d) =/=

68. What is the result of 4 ** 0.5?


a) 2
b) 4
c) 16
d) 0

69. What does list("abc") return?


a) ['a', 'b', 'c']
b) ['abc']
c) 'a b c'
d) ('a', 'b', 'c')

70. What is the output of print("a" in "apple")?


a) True
b) False
c) Error
d) None

71. What is the default separator in print()?


a) space
b) newline
c) comma
d) tab

72. What does this code print?


x = None

print(x is None)

a) True
b) False
c) None
d) Error

73. How do you define a function that takes parameters?


a) def func(x, y):
b) function func(x, y):
c) define func(x, y):
d) func(x, y):

74. What is the output of print("Hello".lower())?


a) HELLO
b) hello
c) Hello
d) hELLO

75. What does max([1, 4, 2]) return?


a) 1
b) 2
c) 4
d) Error

76. What is the output of print("Python"[1])?


a) P
b) y
c) t
d) h
77. How do you concatenate two strings a and b?
a) a + b
b) a & b
c) concat(a, b)
d) a . b

78. What does abs(-7) return?


a) -7
b) 7
c) 0
d) Error

79. What does round(3.6) return?


a) 3
b) 4
c) 3.6
d) Error

80. What is the output of print(10 > 5)?


a) True
b) False
c) 1
d) 0

81. Which function returns the smallest item in a list?


a) min()
b) max()
c) small()
d) first()

82. What does float("3.14") return?


a) 3
b) "3.14"
c) 3.14
d) Error

83. Which data type is returned by input()?


a) str
b) int
c) float
d) bool

84. What will this code print?


if not False:

print("Yes")

a) Yes
b) No
c) False
d) Error

85. How do you make a string uppercase?


a) upper()
b) toUpperCase()
c) capitalize()
d) up()

86. What is the output of print("apple".find("p"))?


a) 0
b) 1
c) 2
d) -1

87. How do you slice the first three characters of string s?


a) s[:3]
b) s[0:2]
c) s[1:3]
d) s[0:3]

88. What does int("10") + int("5") return?


a) 15
b) 105
c) "15"
d) Error

89. What does list(range(3)) return?


a) [1, 2, 3]
b) [0, 1, 2]
c) [0, 1, 2, 3]
d) [3]

90. What is the output of print(len(" "))?


a) 0
b) 1
c) 2
d) Error

91. What is the result of 5 % 2?


a) 0
b) 1
c) 2
d) 2.5

92. How do you remove all items from a list myList?


a) myList.clear()
b) myList.delete()
c) myList.removeAll()
d) del myList()
93. Which of these is NOT a valid string method?
a) upper()
b) find()
c) split()
d) push()

94. What is the output of print(type(True))?


a) <class 'str'>
b) <class 'bool'>
c) <class 'int'>
d) <class 'NoneType'>

95. How do you write an infinite loop?


a) while True:
b) for True:
c) loop forever:
d) while:

96. What does enumerate() do?


a) Returns index and value pairs
b) Sorts a list
c) Creates a range
d) Reverses a list

97. How do you import just the sqrt function from math?
a) from math import sqrt
b) import sqrt from math
c) use math.sqrt
d) include sqrt

98. What is the result of "2" * 3?


a) "222"
b) 6
c) "6"
d) Error

99. What does sum([1,2,3]) return?


a) 3
b) 6
c) [1,2,3]
d) Error

100. What does print(bool([])) output?


a) True
b) False
c) None
d) Error

You might also like