: Python Programming Language :
Set - III
Multiple Choice Questions:
1. Which of the following is a valid string in Python?
A. 'Hello'
B. "Hello"
C. '''Hello'''
D. All of the above
2. What is the output of print("Python"[1:4])?
A. yth
B. Pyt
C. tho
D. ytho
3. What does r"hello\nworld" print?
A. hello (newline) world
B. hello\nworld
C. Syntax Error
D. None
4. Which of the following are Python tokens?
A. Identifiers
B. Literals
C. Operators
D. All of the above
5. Which of these is not a string method in Python?
A. upper()
B. isalpha()
C. reverse()
D. strip()
6. What is the output of 'abc' * 3?
A. abcabcabc
B. abc*3
C. Error
D. abc abc abc
7. Which operator is used for string concatenation?
A. *
B. +
C. &
D. ^
8. The result of len("Python") is:
A. 5
B. 6
C. 7
D. Error
9. What will print("abcde"[-3:]) output?
A. abc
B. cde
C. bcd
D. Error
10. Which of the following is a raw string?
A. r"Hello\nWorld"
B. "Hello\nWorld"
C. 'Hello\\nWorld'
D. R'Hello\nWorld'
11. In Python, string is:
A. Mutable
B. Immutable
C. Optional
D. Dynamic
12. What is the character set used in Python 3?
A. ASCII
B. ANSI
C. Unicode
D. UTF-7
13. Which operator is used for exponentiation in Python?
A. ^
B. **
C. exp()
D. pow()
14. What does a += 3 mean?
A. a = a + 3
B. a = 3
C. Add 3 to a only if a is greater than 0
D. Error
15. In Python, which of these is not a type of literal?
A. String literal
B. Integer literal
C. Boolean literal
D. Control literal
16. Which of the following is not a valid Python identifier?
A. _abc
B. abc_123
C. 123abc
D. abc
17. What does s[:3] return if s = "Python"?
A. Pyt
B. tho
C. hon
D. yth
18. Which of the following is not an assignment operator?
A. =
B. +=
C. ==
D. *=
19. Which of the following keywords is used for defining a class in Python?
A. object
B. define
C. class
D. type
20. Python follows which type of programming paradigm?
A. Procedural
B. Object-Oriented
C. Functional
D. All of the above
21. What will print ("Python"[: -1]) output?
A. nohtyP
B. Python
C. Error
D. Pytho
22. In OOP, what is an instance of a class called?
A. Method
B. Object
C. Function
D. Constructor
23. What is the default return value of a function that does not have a
return statement?
A. 0
B. None
C. False
D. Empty string
24. Which of the following is a relational operator in Python?
A.! =
B. ==
C. >
D. All of the above
25. What will be the result of the following code?
if True:
print("Yes")
else:
print("No")
A. Yes
B. No
C. Error
D. Nothing
26. Which keyword is used to define a function in Python?
A. func
B. function
C. def
D. define
27. Which of the following data types is immutable?
A. List
B. Dictionary
C. Set
D. Tuple
28. What will print (type ('5')) ` return?
A. `<class 'int'>`
B. `<class 'str'>`
C. `<class 'float'>`
D. Error
29. What is the output of `print ('a' > 'b’) `?
A. True
B. False
C. Error
D. Depends on encoding
30. Which character is used for comments in Python?
A. //
B. /**/
C. #
D. --
31. What is the output of `"hello”. capitalize() `?
A. `Hello`
B. `HELLO`
C. `hello`
D. `hELLO`
32. Which of the following is used to inherit a class in Python?
A. `: `
B. `extends`
C. `inherits`
D. `()`
33. Which of the following is not a keyword in Python?
A. `finally`
B. `try`
C. `switch`
D. `raise`
34. What is the output of `'abc'.isalpha()`?
A. True
B. False
C. Error
D. None
35. What will be the value of `x` after this code?
python
x=5
x x= 3
A. 8
B. 15
C. 5
D. Error
36. Which of the following is the correct syntax to check if `x` is not equal to
`y`?
A. `x! = y`
B. `x <> y`
C. `x not = y`
D. `x =! y`
37. What will be the output of this code?
python
a = "hello"
print (a [1:3])
A. `he`
B. `el`
C. `ll`
D. `lo`
38. Which of these defines a class in Python correctly?
A. `class MyClass:`
B. `class MyClass()`
C. `define MyClass:`
D. `MyClass class:`
39. Which method converts all characters to lowercase?
A. `lowercase()`
B. `lower()`
C. `smallcase()`
D. `toLower()`
40. What will be printed?
python
x = 10
if x > 5 and x < 15:
print("OK")
A. OK
B. Error
C. Nothing
D. Syntax Error
41. Which of the following is a logical operator?
A. and
B. or
C. not
D. All of the above
42. Which of the following is not a type of token in Python?
A. Comments
B. Identifiers
C. Expressions
D. Operators
43. Which is true about string slicing?
A. The end index is exclusive
B. The start index is inclusive
C. Negative indices can be used
D. All of the above
44. Which keyword is used for creating a new object?
A. new
B. create
C. object
D. None (object is created using class call)
45. Which of the following is a comparison operator in Python?
A. &&
B. ==
C.! ==
D. ><
46. What is the result of this expression: "5" + "10"?
A. 15
B. 510
C. Error
D. 5 + 10
47. Which function is used to get user input in Python 3?
A. read()
B. scan()
C. input()
D. get()
48. What is the output of print (''.join(['P', 'y', 't', 'h', 'o', 'n']))?**
A. ['Python']
B. Python
C. P y t h o n
D. None
49. What does class Dog: define?
A. A function
B. A string
C. A class
D. A variable
50. What does x // y do in Python?
A. Floating division
B. Exponentiation
C. Integer division
D. Error
: Python Programming Language :
Set - IV
Multiple Choice Questions:
1. Which of the following is not a type of translator?
A. Compiler
B. Interpreter
C. Debugger
D. Assembler
2. Which translator converts high-level code into machine code at once?
A. Interpreter
B. Compiler
C. Assembler
D. Debugger
3. Syntax errors occur:
A. During runtime
B. During compilation
C. After execution
D. When importing modules
4. Which of the following is an example of a logical error?
A. Division by zero
B. Typing print instead of print
C. Incorrect output with no error
D. Missing colon in if statement
5. Which is not a feature of Object-Oriented Programming?
A. Inheritance
B. Encapsulation
C. Compilation
D. Polymorphism
6. Which OOP principle binds data and functions together?
A. Inheritance
B. Polymorphism
C. Encapsulation
D. Abstraction
7. Python is:
A. Interpreted
B. Dynamically typed
C. Open source
D. All of the above
8. Which of the following is not a feature of Python?
A. Platform dependent
B. Readable
C. Dynamic
D. High-level
9. What does the escape sequence \t represent?
A. Newline
B. Backspace
C. Tab
D. Carriage return
10. Which escape sequence represents a new line?
A. \n
B. \t
C. \\
D. \"
11. Which of the following is a Python keyword?
A. define
B. class
C. include
D. Main
12. Identifiers in Python can include:
A. Letters
B. Digits (not starting with)
C. Underscores
D. All of the above
13. Which of the following is a valid identifier?
A. 1value
B. my-value
C. _value1
D. for
14. Which punctuation is used to start a function block?
A.;
B. ()
C.:
D. {}
15. What is the output of print("Line1\nLine2")?
A. Line1 Line2
B. Line1\nLine2
C. Line1
Line2
D. Syntax error
16. Which is an arithmetic operator in Python?
A. +
B. //
C. *
D. All of the above
17. What does >> do in Python?
A. Logical right shift
B. Bitwise AND
C. Bitwise OR
D. Floor division
18. Which operator is used for identity comparison?
A. ==
B. is
C. =
D.! =
19. Which of these is a membership operator?
A. ==
B. in
C. is
D. &&
20. Which of the following is not an assignment operator?
A. +=
B. *=
C. ^=
D. ==
21. Bitwise XOR operator is:
A. ^
B. &
C. |
D. ~
22. What is the result of bin (5 << 1)?
A. '0b1010'
B. '0b100'
C. '0b11'
D. '0b1'
23. Which type of casting is performed automatically by Python?
A. Implicit
B. Explicit
C. Manual
D. Forced
24. Which function is used for explicit type conversion to integer?
A. toInt()
B. int()
C. cast()
D. int_cast()
25. What is the output of len("Python")?
A. 5
B. 6
C. 7
D. Error
26. How do you define a multi-line string in Python?
A. 'This is a string'
B. '''This is a string'''
C. """This is a string"""
D. B and C
27. Which of the following aligns text to the right?
A. rjust()
B. ljust()
C. center()
D. align()
28. What will 'Python'.ljust(10, '*') return?
A. Python****
B. ****Python
C. Python
D. Error
29. What is type (3 + 4.5)?
A. int
B. float
C. complex
D. str
30. Which of the following is a valid escape character?
A. \\
B. \'
C. \"
D. All of the above
31. How many shift operators does Python support?
A. 1
B. 2
C. 3
D. 4
32. Which is the correct way to cast 7.89 to an integer?
A. int(7.89)
B. cast(7.89)
C. toInt(7.89)
D. float(7.89)
33. Which operator checks if two operands refer to the same object?
A. ==
B. is
C.!=
D. equals()
34. Python supports which type of casting?
A. Only implicit
B. Only explicit
C. Both
D. None
35. What is the default padding character in str.ljust()?
A. -
B. ' '
C. *
D. .
36. Which of the following is not a comparison operator?
A. >
B. >=
C. !=
D. &
37. Which of the following is an invalid keyword?
A. True
B. None
C. val
D. if
38. What is the output of print("abc".center(7, '-'))?
A. --abc--
B. abc---
C. ---abc
D. abc
39. What does type('abc') return?
A. str
B. string
C. char
D. text
40. Which of these is NOT a valid type of operator in Python?
A. Arithmetic
B. Logical
C. Bitwise
D. Pointer
41. What is returned by "abc".zfill(5)?
A. 00abc
B. abc00
C. abc
D. 0abc0
42. Which operator would you use to perform a left shift by 2 bits?
A. >>
B. <<
C. **
D. ||
43. Which of the following is a reserved keyword in Python?
A. main
B. var
C. lambda
D. define
44. Which operator returns the remainder of division?
A. /
B. //
C. %
D. *
45. What is the output of type(str(123))?
A. <class 'int'>
B. <class 'float'>
C. <class 'str'>
D. <class 'bool'>
46. 5 >> 1 evaluates to:
A. 10
B. 2
C. 5
D. 1
47. Which keyword is used to define a constant in Python?
A. const
B. final
C. No specific keyword
D. define
48. What is the size of string "abcd" using len()?
A. 3
B. 4
C. 5
D. Error
49. Multiline strings in Python can be used as:
A. Comments
B. Docstrings
C. Literal values
D. All of the above
50. What will 'abc'.rjust(6, '#') return?
A. abc###
B. ###abc
C. abcabc
D. abc
: Python Programming Language :
: Set – V :
1. Which module is used to generate random numbers in Python?
A) math
B) random
C) numpy
D) numbers
2. What does random.randint(1,5) return?
A) A float between 1 and 5
B) An integer between 1 and 5
C) An integer greater than 5
D) A random float
3. Which function is used to generate a random float between 0 and 1?
A) random.randint()
B) random.random()
C) random.uniform()
D) random.float()
4. What will random.uniform(2,8) return?
A) Integer between 2 and 8
B) Float between 0 and 1
C) Float between 2 and 8
D) None
5. Which function returns a random element from a list?
A) random.choice()
B) random.select()
C) random.pick()
D) random.element()
6. What is the output of type(5)?
A) <class 'int'>
B) <class 'float'>
C) <class 'str'>
D) <class 'bool'>
7. What is the type of "123" in Python?
A) Integer
B) Float
C) String
D) Boolean
8. Which function checks the data type of a variable?
A) isinstance()
B) type()
C) datatype()
D) typeof()
9. What is the output of type(5.0)?
A) int
B) float
C) string
D) bool
10. What is the output of type(True)?
A) bool
B) int
C) string
D) list
11. Which of the following can store multiple data types?
A) list
B) int
C) str
D) bool
12. What is the type of [1, "abc", 3.5]?
A) str
B) dict
C) list
D) tuple
13. Which structure allows you to store key-value pairs?
A) list
B) tuple
C) dictionary
D) set
14. Which of the following can contain duplicate elements?
A) set
B) dictionary
C) list
D) All of the above
15. What is the output type of (5, "hello", 3.2)?
A) list
B) set
C) tuple
D) dictionary
16. How can you take a single integer input from the user?
A) int(input())
B) input()
C) float(input())
D) str(input())
17. Which of the following methods can be used to take multiple integer
inputs at once?
A) map(int, input().split())
B) split(int(input()))
C) int(map(input()))
D) input().int().split()
18. What is the output type of input().split()?
A) string
B) list
C) tuple
D) integer
19. Which function is used to convert input into an integer?
A) str()
B) int()
C) float()
D) bool()
20. To accept 3 integers in one line, we can write:
A) input().split(int)
B) map(int, input().split())
C) split(map(int))
D) input().splitint()
21. How do you accept a single string from the user?
A) input()
B) int(input())
C) float(input())
D) str(input())
22. How can you accept multiple strings in a single line?
A) input().split()
B) map(str, input().split())
C) Both A and B
D) None
23. What does split() function do?
A) Joins strings
B) Breaks string into a list
C) Converts string to integer
D) Converts string to tuple
24. Which keyword is used to join multiple strings?
A) join()
B) split()
C) connect()
D) combine()
25. In input().split(','), what is the delimiter?
A) Space
B) Comma
C) Dot
D) Slash
26. Which method reads entire input as a single string?
A) read()
B) input()
C) stdin()
D) gets()
27. How can you separate console input values?
A) Comma
B) Space
C) Any custom separator
D) All of these
28. In input().split(), default delimiter is:
A) Comma
B) Space
C) Tab
D) None
29. If user enters 4,5,6 in input, which split separator will you use?
A) space
B) comma (,)
C) tab
D) semicolon
30. Which of these converts input into list of integers?
A) map(int, input())
B) map(int, input().split())
C) input().map(int())
D) int(map(input()))
31. What is the default value of end in print()?
A) Space
B) Newline \n
C) Comma
D) Dot
32. What will print('Hello', end='!') output?
A) Hello!
B) Hello
C) Hello !
D) Hello\n
33. In print(1,2,3, sep=','), what will be printed?
A) 123
B) 1,2,3
C) 1 2 3
D) 1-2-3
34. Which of the following can modify separation in print()?
A) end
B) sep
C) both
D) none
35. How many arguments print() function accepts?
A) 1
B) 2
C) Many
D) None
36. What does print(1,2,3, sep='-', end='*') output?
A) 1-2-3*
B) 1 2 3*
C) 1-2-3
D) 123*
37. In print('A','B',sep=':',end='@'), output will be:
A) A B
B) A:B@
C) A@B
D) A:B
38. The argument end='' results in:
A) No line break
B) Double line break
C) Line break after each word
D) Error
39. sep is used to:
A) Separate arguments
B) End the print
C) Add newline
D) None
40. If no sep is given, Python separates print arguments with:
A) Comma
B) Space
C) Tab
D) Newline
41. Which is valid print() syntax?
A) print(5,6,7)
B) print(5;6;7)
C) print{5 6 7}
D) print<5,6,7>
42. How can you print multiple lines in one print()?
A) Use \n
B) Use ,
C) Use sep
D) Use end
43. print('A','B','C', sep='*') gives:
A) ABC
B) ABC
C) A B C
D) A B*C
44. print('Welcome', end='@') prints:
A) Welcome@
B) Welcome
C) Welcome @
D) Error
45. How to avoid newline after printing?
A) Use end=' '
B) Use sep=','
C) Use end=''
D) Use \n
46. Which of these prints two numbers without space?
A) print(5,6)
B) print(5,6,sep='')
C) print(5 6)
D) print(5, 6, end='')
47. Which character represents newline?
A) \t
B) \n
C) \\
D) /n
48. What will print('Hi',end='\t') output?
A) Hi with space
B) Hi with tab
C) Hi with newline
D) Error
49. In Python, to add a blank line you can use:
A) print()
B) print('')
C) Both A and B
D) None
50. What is printed by print('Hello','World',sep='-')?
A) Hello World
B) Hello-World
C) HelloWorld
D) Hello - World
: Python Programming Language :
: Set – VI :
1. Which module is used to generate random numbers in Python?
A) math
B) random
C) numbers
D) randint
2. What function generates a random integer between two values?
A) random()
B) rand()
C) randint(a, b)
D) randomint(a, b)
3. Which function generates a random floating number between 0 and 1?
A) random.randint()
B) random.random()
C) random.uniform()
D) random.float()
4. random.choice() function is used to:
A) Generate random float
B) Pick a random item from a list
C) Pick a random number from a range
D) Shuffle a list
5. What is the output type of random.random()?
A) Integer
B) Float
C) Boolean
D) String
6. What is the type of data returned by input() function?
A) int
B) str
C) float
D) bool
7. Which type is mutable in Python?
A) tuple
B) list
C) str
D) int
8. What is the data type of True?
A) int
B) bool
C) float
D) str
9. What is the result type of 3 + 2.0?
A) int
B) float
C) complex
D) bool
10. 3j in Python refers to what type?
A) int
B) float
C) complex
D) bool
11. In Python, a list can contain:
A) Only integers
B) Only strings
C) Only floats
D) Different types of data
12. What is the correct way to define a list with multiple data types?
A) [1, 'hello', 3.14]
B) (1, 2, 3)
C) {1, 2, 3}
D) None of the above
13. A tuple can contain:
A) Only strings
B) Mixed data types
C) Only numbers
D) Only floats
14. Which of the following is an example of a dictionary with mixed data?
A) {1: 'a', 2: 'b'}
B) [1, 'a']
C) (1, 'a')
D) None
15. Which of the following stores multiple integers?
A) Set
B) List
C) Dictionary
D) All of the above
16. How do you take single integer input from user?
A) input()
B) int(input())
C) float(input())
D) str(input())
17. How can you input multiple integers in one line?
A) map(int, input().split())
B) input().split(',')
C) int(input().split())
D) input().split(int)
18. What is the data type of input taken by input() without any conversion?
A) int
B) float
C) bool
D) str
19. Which function is used to split multiple values?
A) split()
B) cut()
C) divide()
D) none
20. What is the output of list(map(int, input().split())) if input is 1 2 3?
A) [1, 2, 3]
B) (1,2,3)
C) {1,2,3}
D) Error
21. To take a single string input, you use:
A) str(input())
B) input()
C) int(input())
D) bool(input())
22. How to take multiple string inputs separated by spaces?
A) input().split()
B) input()
C) split.input()
D) input().break()
23. In multiple string input, input().split() returns:
A) A tuple
B) A list
C) A dictionary
D) A string
24. What is the output of input().split() if input is a b c?
A) ['a', 'b', 'c']
B) (a, b, c)
C) {'a', 'b', 'c'}
D) abc
25. In Python, strings are:
A) Mutable
B) Immutable
C) Both
D) None
26. Which of the following reads input as string?
A) input()
B) int(input())
C) float(input())
D) bool(input())
27. Which input function is preferred for integer input?
A) int(input())
B) input()
C) float(input())
D) bool(input())
28. Which input function is used to take decimal numbers?
A) input()
B) float(input())
C) int(input())
D) bool(input())
29. Which method is used to separate values by a delimiter in input?
A) split(delimiter)
B) divide(delimiter)
C) cut(delimiter)
D) input().break()
30. input().split(',') splits input based on:
A) space
B) tab
C) comma
D) colon
31. What does end parameter in print() do?
A) Changes separator
B) Ends line
C) Adds at end instead of new line
D) None
32. What does print('Hello', end='!') output?
A) Hello!
B) Hello
C) Hello! (new line)
D) Error
33. sep parameter in print() is used to:
A) Separate different print statements
B) Separate different values inside one print
C) End a print statement
D) None
34. What is the output of print(1,2,3, sep='-')?
A) 1-2-3
B) 1 2 3
C) 1,2,3
D) 123
35. Which combination uses both sep and end?
A) print(1,2, sep='*', end='#')
B) print(1,2, end='*', sep='#')
C) print(1,2, sepend='*')
D) None
36. print("Hello", "World", sep='-') gives:
A) Hello-World
B) Hello World
C) Hello,World
D) Error
37. What is the default sep value in print()?
A) '' (empty string)
B) ','
C) ' ' (space)
D) None
38. What is the default end value in print()?
A) ' '
B) '\n'
C) '!'
D) '\t'
39. print(5, 6, 7, end='') will end the output with:
A) nothing
B) **
C) \n
D) 56
40. print('a', 'b', 'c', sep='*', end='@') outputs:
A) abc@
B) a b c@
C) abc
D) Error
41. Boolean values can be:
A) 0 and 1
B) True and False
C) 'True' and 'False'
D) 1 and -1
42. What is the output of bool(0)?
A) True
B) False
C) None
D) Error
43. What is the output of bool(10)?
A) True
B) False
C) None
D) 0
44. What will be the output of print(True + False)?
A) 0
B) 1
C) TrueFalse
D) Error
45. What is the type of True?
A) str
B) int
C) bool
D) float
46. Which value will return False in boolean context?
A) Non-empty list
B) 0
C) Non-zero number
D) Non-empty string
47. The value of bool('False') is:
A) True
B) False
C) None
D) Error
48. The output of bool([]) is:
A) True
B) False
C) []
D) Error
49. What is the output of bool(' ') (single space)?
A) True
B) False
C) None
D) Error
50. In Python, boolean type is a subclass of:
A) str
B) list
C) int
D) tuple