प्रश्न 1 : Which type of Programming does Python support?
a) object-oriented programming
b) structured programming
c) functional programming
d) all of the mentioned
Answer: d
Explanation: Python is an interpreted programming language, which supports object-oriented, structured, and functional programming.
प्रश्न 2 : Is Python case sensitive when dealing with identifiers?
a) no
b) yes
c) machine dependent
d) none of the mention
Answer: b
Explanation: Case is always significant while dealing with identifiers in python.
प्रश्न 3 : Is Python code compiled or interpreted?
a) Python code is both compiled and interpreted
b) Python code is neither compiled nor interpreted
c) Python code is only compiled
d) Python code is only interpreted
Answer: a
Explanation: Many languages have been implemented using both compilers and interpreters, including C, Pascal, and Python.
प्रश्न 4 : All keywords in Python are in _________a) Capitalized
b) lower case
c) UPPER CASE
d) None of the mentioned
Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.
प्रश्न 5 : What will be the value of the following Python expression?
4 + 3 % 5
a) 7
b) 2
c) 4
d) 1
Answer: a
Explanation: The order of precedence is: %, +. Hence the expression above, on simplification results in 4 + 3 = 7. Hence the result is 7.
प्रश्न 6 : Which of the following is used to define a block of code in Python language?
a) Indentation
b) Key
c) Brackets
d) All of the mentioned
Answer: a
प्रश्न 7 : Which keyword is used for function in Python language?
- a) Function
b) def
c) Fun
d) Define
Answer: b
Explanation: The def keyword is used to create, (or define) a function in python.
प्रश्न 8 : Which of the following functions can help us to find the version of python that we are currently working on?
a) sys.version(1)
b) sys.version(0)
c) sys.version()
d) sys.version
Answer: d
Explanation: The function sys.version can help us to find the version of python that we are currently working on. It also contains information on the build number and compiler used. For example, 3.5.2, 2.7.3 etc. this function also returns the current date, time, bits etc along with the version.
प्रश्न 9 : Python supports the creation of anonymous functions at runtime, using a construct called __________ a) pi
b) anonymous
c) lambda
d) none of the mentioned
Answer: c
Explanation: Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called lambda. Lambda functions are restricted to a single expression. They can be used wherever normal functions can be used.
प्रश्न 10 : What will be the output of the following Python code snippet if x=1?
- a) 4
b) 2
c) 1
d) 8
Answer: a
Explanation: The binary form of 1 is 0001. The expression x<<2 implies we are performing bitwise left shift on x. This shift yields the value: 0100, which is the binary form of the number 4.
प्रश्न 11 : What does pip stand for python?a) Pip Installs Python
b) Pip Installs Packages
c) Preferred Installer Program
d) All of the mentioned
Answer: c
Explanation: pip is a package manager for python. Which is also called Preferred Installer Program.
प्रश्न 12 : Which of the following is true for variable names in Python?
a) underscore and ampersand are the only two special characters allowed
b) unlimited length
c) all private members must have leading and trailing underscores
d) none of the mentioned
Answer: b
Explanation: Variable names can be of any length.
प्रश्न 13 : Which of the following is the truncation division operator in Python?
a) |
b) //
c) /
d) %
Answer: b
Explanation: // is the operator for truncation division. It is called so because it returns only the integer part of the quotient, truncating the decimal part. For example: 20//3 = 6.
प्रश्न 14 : Which of the following is the use of id() function in python?
a) Every object doesn’t have a unique id
b) Id returns the identity of the object
c) All of the mentioned
d) None of the mentioned
Answer: b
Explanation: Each object in Python has a unique id. The id() function returns the object’s id.
प्रश्न 15 : Which of the following is not a core data type in Python programming?
a) Tuples
b) Lists
c) Class
d) Dictionary
Answer: c
Explanation: Class is a user-defined data type.
प्रश्न 16 : Which of these is the definition for packages in Python?
a) A set of main modules
b) A folder of python modules
c) A number of files containing Python definitions and statements
d) A set of programs making use of Python modules
Answer: b
Explanation: A folder of python programs is called as a package of modules.
प्रश्न 17 : Which one of the following is not a keyword in Python language?
a) pass
b) eval
c) assert
d) nonlocal
Answer: b
Explanation: eval can be used as a variable.
प्रश्न 18 : Which module in the python standard library parses options received from the command line?
a) getarg
b) getopt
c) main
d) os
Answer: b
Explanation: getopt parses options received from the command line.
प्रश्न 19: Which of the following statements is used to create an empty set in Python?
a) ( )
b) [ ]
c) { }
d) set()
Answer: d
Explanation: { } creates a dictionary not a set. Only set() creates an empty set.
प्रश्न 20 : To add a new element to a list we use which Python command? a) list1.addEnd(5)
b) list1.addLast(5)
c) list1.append(5)
d) list1.add(5)
Answer: c
Explanation: We use the function append to add an element to the list.
प्रश्न 21 : Which one of the following is the use of function in python?
a) Functions don’t provide better modularity for your application
b) you can’t also create your own functions
c) Functions are reusable pieces of programs
d) All of the mentioned
Answer: c
Explanation: Functions are reusable pieces of programs. They allow you to give a name to a block of statements, allowing you to run that block using the specified name anywhere in your program and any number of times.
प्रश्न 22 : What is the maximum possible length of an identifier in Python?
a) 79 characters
b) 31 characters
c) 63 characters
d) none of the mentioned
Answer: d
Explanation: Identifiers can be of any length.
प्रश्न 23 : What are the two main types of functions in Python?
a) System function
b) Custom function
c) Built-in function & User defined function
d) User function
Answer: c
Explanation: Built-in functions and user defined ones. The built-in functions are part of the Python language. Examples are: dir(), len() or abs(). The user defined functions are functions created with the def keyword.
प्रश्न 24 : Which of the following is the use of id() function in python?
a) Every object in Python doesn’t have a unique id
b) In Python Id function returns the identity of the object
c) None of the mentioned
d) All of the mentioned
Answer: b
Explanation: Each object in Python has a unique id. The id() function returns the object’s id.
प्रश्न 25 : What is the maximum possible length of an identifier? a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned
Answer: d
Explanation: Identifiers can be of any length.
प्रश्न 26 : Which of the following is invalid?
a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned
Answer: d
Explanation: All the statements will execute successfully but at the cost of reduced readability.
उत्तर : प्रश्न 27 : Which of the following is an invalid variable?
a) my_string_1
b) 1st_string
c) foo
d) _
Ans: b
Explanation: Variable names should not start with a number.
प्रश्न 28 : Which of the following cannot be a variable?
a) __init__
b) in
c) it
d) on
Answer: b
Explanation: in is a keyword.
प्रश्न 29 : Which function is called when the following Python code is executed?
f = foo()
format(f)
- a) format()
b) __format__()
c) str()
d) __str__()
Answer: d
Explanation: Both str(f) and format(f) call f.__str__().
प्रश्न 30 : Which function overloads the + operator?
a) __add__()
b) __plus__()
c) __sum__()
d) none of the mentioned
Answer: a
Explanation: Refer documentation.
प्रश्न 31 : Which operator is overloaded by __invert__()?
a) !
b) ~
c) ^
d) –
Answer: b
Explanation: __invert__() overloads ~.
प्रश्न 32 : Which function overloads the == operator?
a) __eq__()
b) __equ__()
c) __isequal__()
d) none of the mentioned
Answer: a
Explanation: The other two do not exist.
प्रश्न 33 : Which operator is overloaded by __lg__()?
a) <
b) >
c) !=
d) none of the mentioned
Answer: d
Explanation: __lg__() is invalid.
प्रश्न 34 : Which function overloads the >> operator?
a) __more__()
b) __gt__()
c) __ge__()
d) none of the mentioned
Answer: d
Explanation: __rshift__() overloads the >> operator.
प्रश्न 35 : Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
a) __add__(), __str__()
b) __str__(), __add__()
c) __sum__(), __str__()
d) __str__(), __sum__()
Answer: a
Explanation: The function __add__() is called first since it is within the bracket. The function __str__() is then called on the object that we received after adding A and B.
प्रश्न 36 : Which operator is overloaded by the __or__() function?
a) ||
b) |
c) //
d) /
Answer: b
Explanation: The function __or__() overloads the bitwise OR operator |.
प्रश्न 37 : Which function overloads the // operator?
a) __div__()
b) __ceildiv__()
c) __floordiv__()
d) __truediv__()
Answer: c
Explanation: __floordiv__() is for //.
प्रश्न 38 : Which is the correct operator for power(xy)?
a) X^y
b) X**y
c) X^^y
d) None of the mentioned
Answer: b
Explanation: In python, power operator is x**y i.e. 2**3=8.
प्रश्न 39 : Which one of these is floor division?
a) /
b) //
c) %
d) None of the mentioned
Answer: b
Explanation: When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. This is floor division. For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. To get the 2.5 answer, use floor division.
प्रश्न 40 : What is the order of precedence in python?
i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction
Answer: a
Explanation: For order of precedence, just remember this PEMDAS (similar to BODMAS).
प्रश्न 41 : Mathematical operations can be performed on a string.
a) True
b) False
Answer: b
Explanation: You can’t perform mathematical operation on string even if the string is in the form: ‘1234…’.
प्रश्न 42 : Operators with the same precedence are evaluated in which manner?
a) Left to Right
b) Right to Left
c) Can’t say
d) None of the mentioned
Answer: a
Explanation: None.
प्रश्न 43 : Which one of the following has the same precedence level?
a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication
Answer: a
Explanation: “Addition and Subtraction” are at the same precedence level. Similarly, “Multiplication and Division” are at the same precedence level. However, Multiplication and Division operators are at a higher precedence level than Addition and Subtraction operators.
प्रश्न 44 : Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
Answer: d
Explanation: Just remember: PEMDAS, that is, Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction. Note that the precedence order of Division and Multiplication is the same. Likewise, the order of Addition and Subtraction is also the same.
प्रश्न 45 : Which of these in not a core data type?
a) Lists
b) Dictionary
c) Tuples
d) Class
Answer: d
Explanation: Class is a user defined data type.
प्रश्न 46 : Given a function that does not return any value, What value is thrown by default when executed in shell.
a) int
b) bool
c) void
d) None
Answer: d
Explanation: Python shell throws a NoneType object back.
प्रश्न 47 : What is the return type of function id?
a) int
b) float
c) bool
d) dict
Answer: a
Explanation: Execute help(id) to find out details in python shell.id returns a integer value that is unique.
प्रश्न 48 : In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
Answer: d
Explanation: Dictionary stores values in terms of keys and values.
प्रश्न 49 : What is the return value of trunc()?
a) int
b) bool
c) float
d) None
Answer: a
Explanation: Execute help(math.trunc) to get details. A
प्रश्न 50 : What data type is the object below?
L = [1, 23, ‘hello’, 1]a) list
b) dictionary
c) array
d) tuple
Answer: a
Explanation: List data type can store any values within it.