Page | 1
iNeuron Intelligence Pvt Ltd
Q1. Define Dictionary.
Ans- a) Unordered sets of objects.
b) Also known as maps, hashmaps, lookup tables, or associative array.
c) Data exists in key-value pair. Elements in dictionary have a key and a
corresponding value. The key and the value are separated from each other
with a colon “:” and all elements are separated by comma.
d) Elements of a dictionary are accessed by the “key” and not by index.
Hence it is more or less like an associative array where every key is
associated with a value and elements exists in an unordered fashion as key-
value pair.
e) Dictionary literals use curly brackets ‘ {}’.
Q2. How can we create a dictionary object?
Ans- A dictionary object can be created in any of the following ways:
# Initializing an empty Dictionary
Dictionary = {}
print("An empty Dictionary: ")
print(Dictionary)
# Creating a Dictionary using in-built dict() method
Dictionary = dict({1: 'Python', 2: 'Java', 3:'Dictionary'})
print("\nDictionary created by using dict() method: ")
print(Dictionary)
# Creating dictionary by key: value pair format
Dictionary = dict([(1, 'Java'), (2, 'Python'), (3, 'Dictionary')])
print("\nDictionary with key: value pair format: ")
print(Dictionary)
Page | 2
iNeuron Intelligence Pvt Ltd
Q3. Explain from Keys () method.
Ans- The form keys () method returns a new dictionary that will have the
same keys as the dictionary object passed as the argument. If you provide a
value then all keys will be set to that value or else all keys will be set to
‘None’.
Q4. What is the purpose of items() function?
Ans- the items() function does not take any parameters. It returns the view
object that shows the given dictionary’s key value pairs.
Q5. Define bucket sorting?
Ans- Bucket Sort is a two-step procedure for sorting data. First, the values are
collected in special containers called buckets. Then, these values are
transferred appropriately into a sorted list. For the algorithm to be feasible,
the elements to be sorted must have a limited set of values.
Page | 3
iNeuron Intelligence Pvt Ltd
Q6. Which one of the following is correct way of declaring and initialising a
variable, x with value 5?
A. int x
x=5
B. int x=5
C. x=5
D. declare x=5
Ans: C
Explanation: One of the following is correct way of declaring and initialising
a variable, x with value 5 is x=5.
Q7. How many local and global variables are there in the following
Python code?
var1=5
def fn():
var1=2
var2=var1+5
var1=10
fn()
A. 1 local, 1 global variables
B. 1 local, 2 global variables
C. 2 local, 1 global variables
D. 2 local, 2 global variables
Ans-D. 2 local, 2 global variables
Explanation: 2 local, 2 global variables are there in the following Python
code.
Page | 4
iNeuron Intelligence Pvt Ltd
Q8. Which one is false regarding local variables?
A. These can be accessed only inside owning function
B. Any changes made to local variables does not reflect outside the function.
C. These remain in memory till the program ends
D. None of the above
Ans: C
Explanation: These remain in memory till the program ends is false regarding
local variables.
Q9. Which of the following options will give an error if set1={2,3,4,5}?
A. print(set1[0])
B. set1[0]=9
C. set1=set1+{7}
D. All of the above
Ans : D
Explanation: All of the above option will give error if set1={2,3,4,5}.
Q10. What will be the result of below Python code?
set1= {1,2,3}
[Link] (4)
[Link] (4)
print(set1)
A. {1,2,3,4}
B. {1,2,3}
C. {1,2,3,4,4}
D. It will throw an error as same element is added twice
Ans: A
Explanation: The output for the following python code is {1,2,3,4}.
Page | 5
iNeuron Intelligence Pvt Ltd
______________________________________________________________
Q11. Which of the following options will give an error if set1= {2,3,4,5}?
A. print(set1[0])
B. set1[0] = 9
C. set1=set1 + {7}
D. All of the above
Ans: D
Explanation: All of the above option will give error if set1= {2,3,4,5}
[Link] will the below Python code do?
set1={"a",3,"b",3}
[Link](3)
A. It removes element with index position 3 from set1
B. It removes element 3 from set1
C. It removes only the first occurrence of 3 from set1
D. No such function exists for set
Ans: B
Explanation: It removes element 3 from set1.
Q13. What will be the output of following Python code?
set1= {2,5,3}
set2= {3,1}
set3= {}
set3=set1&set2
print(set3)
A. {3}
B. {}
C. {2,5,3,1}
D. {2,5,1}
Ans: A
Explanation: The output of the following code is {3}
Page | 6
iNeuron Intelligence Pvt Ltd
______________________________________________________________
_____________________________
Q14. Which of the following is True regarding lists in Python?
A. Lists are immutable.
B. Size of the lists must be specified before its initialization
C. Elements of lists are stored in contagious memory location.
D. size(list1) command is used to find the size of lists.
Ans: C
Explanation: Elements of lists are stored in contagious memory location is
True regarding lists in Python.
Q15. Which of the following will give output as [23,2,9,75]?
If list1= [6,23,3,2,0,9,8,75]
A. print(list1[1:7:2])
B. print(list1[0:7:2])
C. print(list1[1:8:2])
D. print(list1[0:8:2])
View Answer
Ans: C
Explanation: print(list1[1:8:2]) of the following will give output as
[23,2,9,75].
Q16. The marks of a student on 6 subjects are stored in a list, list1=
[80,66,94,87,99,95]. How can the student's average mark be calculated?
A. print(avg(list1))
B. print(sum(list1)/len(list1))
C. print(sum(list1)/size of(list1))
D. print(total(list1)/len(list1))
Ans: B
Explanation: the student's average mark be calculated through
print(sum(list1)/len(list1)).
Page | 7
iNeuron Intelligence Pvt Ltd
______________________________________________________________
_____________________________
Q17. What will be the output of following Python code?
list1= ["Python", "Java", "c", "C", "C++"]
print(min(list1))
A. c
B. C++
C. C
D. min function cannot be used on string elements
Ans: C
Explanation: C will be the output of following Python code.
Q18. What will be the result after the execution of above Python code?
list1= [3,2,5,7,3,6]
[Link] (3)
print(list1)
A. [3,2,5,3,6]
B. [2,5,7,3,6]
C. [2,5,7,6]
D. [3,2,5,7,3,6]
Ans: A
Explanation: [3,2,5,3,6] will be the result after the execution of above Python
code.
Page | 8
iNeuron Intelligence Pvt Ltd
______________________________________________________________
_____________________________
Q19. What will be the output of below Python code?
list1=["tom","mary","simon"]
[Link](5,8)
print(list1)
A. ["tom", "mary", "simon", 5]
B. ["tom", "mary", "simon", 8]
C. [8, "tom", "mary", "simon"]
D. Error
Ans: B
Explanation: ["tom", "mary", "simon", 8] will be the result after the execution
of above Python code.
Q20. Which among the following are mutable objects in Python?
(i) List
(ii) Integer
(iii) String
(iv) Tuple
A. i only
B. i and ii only
C. iii and iv only
D. iv only
Ans- A
Explanation: List are mutable objects in Python.
Page | 9
iNeuron Intelligence Pvt Ltd
Q1. Why is Python considered to be a highly versa7le programming
language?
Ans- Python is a high versa1le programming language because it
supports mul1ple models of programming such as:
OOP
Func1onal
Impera1ve
Procedural
Q2. What are the advantages of choosing python over any other
programming language?
Ans- The advantages of choosing python over any other
programming languages are as follows:
ü Extensible in C and C++
ü It is dynamic in nature
ü Easy to learn and easy to implement
ü Third party opera1ng modules are present: As the name
suggests a third-party module is wriDen by third party which
means neither you nor the python writers have developed it.
However, you can make use of these modules to add
func1onality to your code.
Q3. Is python dynamically typed?
Ans - Yes, Python is dynamically typed because in a code we need not
specify the type of variables while declaring them. The type of a
variable is not known un1l the code is executed.
Page 2 of 9
iNeuron Intelligence Pvt Ltd
Q4. What do you mean when you say that Python is an interpreted
language?
Ans – When we say python is an interpreted language it means that
python code is not compiled before execu1on. Code wriDen in
compiled languages such as java can be executed directly on the
processor because it is compiled before run1me and at the 1me of
execu1on it is available in the form of machine language that the
computer can understand.
This is not the case with python. It does not provide code in machine
language before run1me. The transla1on of code to machine
language occurs while the program is being executed.
Q5. Python is a high-level programming language? What is a need
for high level programming languages?
Ans- High level programming languages act as a bridge between the
machine and humans. Coding directly in machine language can be a
very 1me consuming and cumbersome process and it would
definitely restrict coders from achieving their goals. High level
programming languages like Python , JAVA ,C++ , etc are easy to
understand. They are tools which the programmers can use for
advanced level programming.
Q6. Draw the comparison between Java and Python.
JAVA PYTHON
Java is complied. Python is interpreted.
Java is sta1cally typed. Python is dynamically typed.
Java encloses everything in Python follows indenta1on and
braces. makes the code neat and readable.
Page 3 of 9
iNeuron Intelligence Pvt Ltd
Indenta1on also determines the
code execu1on.
Android app development is There are libraries like Kivy which
mostly done using Java and can be used along with the python
XML. code to make it compa1ble for
android development.
Java is stronger when it comes Python connec1vity is not that
to connec1vity with database. strong as Java.
Java is more difficult to learn as Python was developed with focus
compared to python. on making it easy to learn.
Java gives high priority to A good developer can code a secure
security. applica1on in python also.
Q7. Which character set does Python use?
Ans- Python uses tradi1onal ASCII character set.
Q8. What is the purpose of indenta7on in python?
Ans – Indenta1on is one of the most dis1nc1ve features of Python.
While in other programming languages, developers uses indenta1on
to keep their code neat but in case of Python , indenta1on is required
to mark the beginning of a block or to understand which block the
code belongs to. No braces are used to mark block of codes in
python. Block in codes is required to define func1ons, condi1onal
statements, or loops. These blocks are created simply by correct
usage of spaces. All statement that are same distance from the right
belong to the same block.
Page 4 of 9
iNeuron Intelligence Pvt Ltd
Q9. Explain memory management in Python.
Ans- Memory management is required so that par1al or complete
sec1on of computer’s memory can be reserved for execu1ng
programs and processes. This method of providing memory is called
memory alloca1on. Also, when data is no longer required, it must be
removed. Knowledge of memory management helps developer is
develop efficient code.
Everything in Python is an object. Python has different types of
objects, such as simple objects which consist of numbers and strings
and container object such as dic1onary, list, and user defined classes.
These objects can be accessed by an iden1fier -name.
Q 10. Differen7ate between mutable and immutable objects.
Mutable Objects Immutable Objects
Can change their state or Cannot change their state or
contents. contents.
Type: list, dic1onary, set Inbuilt types: int, float, bool, string,
Unicode, tuple
Easy to change Making changes require crea1on of
copy
Customized container like Primi1ve like data types is
types is mostly mutable. immutable.
Q11. What is Variable in Python?
Ans- Variables in Python are reserved memory loca1ons that stores
values. Whenever a variable is created, some space is reserved in the
memory. Based on the data type of a variable, the interpreter will
allocate memory and decide what should be stored in the memory.
Page 5 of 9
iNeuron Intelligence Pvt Ltd
Q12. How can we assign same value to mul1ple variables in one
single go?
Ans- a=b=c= “hello world!”
print(a)
Output - hello world!
print(b)
Output - hello world!
print(c)
Output - hello world!
Q13. What are the methods available for conversion of numbers
from one type to another?
Ans- a = 87.8
#Conversion to integer
print(int(a))
Output
87
# Conversion to float
a=87
print(float(a))
Output
87.0
#Convert to complex
a =87
print(complex(a))
Output
(87+0j)
Q14. What are number data types in python?
Ans- Number data types are the one which are used to store numeric
values such as:
Page 6 of 9
iNeuron Intelligence Pvt Ltd
[Link]
[Link]
3.float
[Link]
a=1
b = -1
c = 1.1
print(type(a))
print(type(b))
print(type(c))
Output
<class ‘int’>
<class ‘int’>
<class ‘float’>
Q15. How to convert real numbers to complex numbers?
a=7
b = -8
x = complex (a, b)
[Link]
Output
7.0
[Link]
Output
-8.0
Page 7 of 9
iNeuron Intelligence Pvt Ltd
Q16. Which of the following is used to define a block of code in
Python language?
a) Indenta1on
b) Key
c) Brackets
d) All of the men1oned
Answer: a
Explana1on: In Python, to define a block of code we use indenta1on.
Indenta1on refers to whitespaces at the beginning of the line.
Q17 Which keyword is used for func1on in Python language?
a) Func1on
b) def
c) Fun
d) Define
Answer: b
Explana1on: The def keyword is used to create, (or define) a func1on
in python.
Q18 Who developed Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
Answer: c
Explana1on: Python language is designed by a Dutch programmer
Guido van Rossum in the Netherlands.
Page 8 of 9
iNeuron Intelligence Pvt Ltd
Q19. Which of the following func1ons can help us to find the version
of python that we are currently working on?
a) sys. version(1)
b) [Link](0)
c) [Link]()
d) [Link]
Answer: d
Explana1on: The func1on sys. version can help us to find the version
of python that we are currently working on. It also contains
informa1on on the build number and compiler used. For example,
3.5.2, 2.7.3 etc. this func1on also returns the current date, 1me, bits
etc along with the version.
Q20. Which of the following is the trunca1on division operator in
Python?
a) |
b) //
c) /
d) %
Answer: b
Explana1on: // is the operator for trunca1on division. It is called so
because it returns only the integer part of the quo1ent, trunca1ng
the decimal part. For example: 20//3 = 6.
Page 9 of 9
iNeuron Intelligence Pvt Ltd
1. Which of the following is not a core data type in Python
programming?
a) Tuples
b) Lists
c) Class
d) Dic@onary
Answer: c
Explana@on: Class is a user-defined data type.
2. Which of these is the defini@on for packages in Python?
a) A set of main modules
b) A folder of python modules
c) A number of files containing Python defini@ons and statements
d) A set of programs making use of Python modules
Answer: b
Explana@on: A folder of python programs is called as a package of
modules.
3. What is the order of namespaces in which Python looks for an
iden@fier?
a) Python first searches the built-in namespace, then the global
namespace and finally the local namespace
b) Python first searches the built-in namespace, then the local
namespace and finally the global namespace
c) Python first searches the local namespace, then the global
namespace and finally the built-in namespace
d) Python first searches the global namespace, then the local
namespace and finally the built-in namespace
Page 2 of 8
iNeuron Intelligence Pvt Ltd
Answer: c
Explana@on: Python first searches for the local, then the global and
finally the built-in namespace.
4. Which one of the following is not a keyword in Python language?
a) pass
b) eval
c) assert
d) nonlocal
Answer: b
Explana@on: eval can be used as a variable.
5. Which module in the python standard library parses op@ons
received from the command line?
a) getarg
b) getopt
c) main
d) os
Answer: b
Explana@on: getopt parses op@ons received from the command line.
6. Which of the following statements is used to create an empty set
in Python?
a) ()
b) [ ]
c) { }
d) set()
Answer: d
Explana@on: {} creates a dic@onary not a set. Only set() creates an
empty set.
Page 3 of 8
iNeuron Intelligence Pvt Ltd
7. Which one of the following is the use of func@on in python?
a) Func@ons do not provide beWer modularity for your applica@on
b) you cannot also create your own func@ons
c) Func@ons are reusable pieces of programs
d) All of the men@oned
Answer: c
Explana@on: Func@ons 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 @mes.
8. What is the maximum possible length of an iden@fier in Python?
a) 79 characters
b) 31 characters
c) 63 characters
d) none of the men@oned
Answer: d
Explana@on: Iden@fiers can be of any length.
9. What are the two main types of func@ons in Python?
a) System func@on
b) Custom func@on
c) Built-in func@on & User defined func@on
d) User func@on
Answer: c
Explana@on: Built-in func@ons and user defined ones. The built-in
func@ons are part of the Python language. Examples are: dir(), len()
or abs(). The user defined func@ons are func@ons created with the
def keyword.
Page 4 of 8
iNeuron Intelligence Pvt Ltd
10. Which of the following is a Python tuple?
a) {1, 2, 3}
b) {}
c) [1, 2, 3]
d) (1, 2, 3)
Answer: d
Explana@on: Tuples are represented with round brackets.
11. Which of the following is the use of id() func@on in python?
a) Every object in Python doesn’t have a unique id
b) In Python Id func@on returns the iden@ty of the object
c) None of the men@oned
d) All of the men@oned
Answer: b
Explana@on: Each object in Python has a unique id. The id() func@on
returns the object’s id.
12. The process of pickling in Python includes ____________
a) conversion of a Python object hierarchy into byte stream
b) conversion of a datatable into a list
c) conversion of a byte stream into Python object hierarchy
d) conversion of a list into a datatable
Answer: a
Explana@on: Pickling is the process of serializing a Python object, that
is, conversion of a Python object hierarchy into a byte stream. The
reverse of this process is known as unpickling.
Page 5 of 8
iNeuron Intelligence Pvt Ltd
13. What is the output of print 0.1 + 0.2 == 0.3?
a) True
b) False
c) Machine dependent
d) Error
Answer: b
Explana@on: Neither of 0.1, 0.2 and 0.3 can be represented
accurately in binary. The round off errors from 0.1 and 0.2
accumulate and hence there is a difference of 5.5511e-17 between
(0.1 + 0.2) and 0.3.
14. Which of the following is not a complex number?
a) k = 2 + 3j
b) k = complex (2, 3)
c) k = 2 + 3l
d) k = 2 + 3J
Answer: c
Explana@on: l (or L) stands for long.
15. Which of the following is incorrect?
a) x = 30963
b) x = 0x4f5
c) x = 19023
d) x = 03964
Answer: d
Explana@on: Numbers star@ng with a 0 are octal numbers but 9 is not
allowed in octal numbers.
Page 6 of 8
iNeuron Intelligence Pvt Ltd
16. What are tokens?
Ans- Tokens are the smallest units of program in Python. There are
four types of tokens in Python:
a) Keywords
b) Iden@fiers
c)Literals
d)Operators
17. What are constants?
Ans- Constants (literals) are values that do not change while
execu@ng a program.
18. What would be the output for 2*4**2? Explain.
Ans- The precedence of ** is higher than precedence of *. Thus, 4**2
will be computed first. The output value is 32 because 4**2 will be
computed first. The output value is 32 because 4**2=16 and
2*16=32.
19. What are operators and operands?
Ans- Operators are the special symbols that represent computa@ons
like addi@on and mul@plica@on. The values the operator uses are
called operands.
The symbols +, -, and /, and the use of parenthesis for grouping,
mean in Python what they mean in mathema@cs. The asterisk (*) is
the symbol of mul@plica@on, and** is the symbol for exponen@a@on.
When a variable name appears in the place of an operand, it is
replaced with its value before the opera@on is performed.
Page 7 of 8
iNeuron Intelligence Pvt Ltd
20. What is the Order of Opera@ons?
Ans- For mathema@cal operators, Python follows mathema@cal
conven@on. The acronym PEMDAS is a useful way to remember the
rules:
a) For mathema@cal operators, Python follows mathema@cal
conven@on. The acronym PEMDAS is a useful way to remember
the rules:
b) Exponen@a@on has the next highest precedence, so 1 + 2**3 is
9, not 27, and 2 * 3**2 is 18, not 36.
c) Mul@plica@on and Division have higher precedence than
Addi@on and Subtrac@on.
Page 8 of 8
iNeuron Intelligence Pvt Ltd
1. Define string, list and Tuple.
Ans- String- They are immutable sequence of text characters. There is
no special class for a single character in Python. A character can be
considered as String of text having a length of 1.
List- Lists are very widely used in Python programming and a list
represents sequence of arbitrary objects. List is immutable.
Tuple-Tuple is more or less like a list but it is immutable.
2. What would be the output for the following expression:
Ans- print (‘{0:4}’. format (7.0 / 3))
3. How can String literals be defined?
Ans- a= “Hello World”
b= ’Hi’
type(a)
<class ‘str’>
Type(b)
<class ‘str’>
c=” Once upon a \me in a land far away there lived a king”
type(c)
<class ‘str’>
4. How can we perform concatena\on of Strings?
Ans -Concatena\on of Strings can be performed using following
techniques:
1) +operator
string1= “Welcome”
string2 = “to the world of Python!!!”
string3 = string1 + string2
print(string3)
Welcome to the world of Python!!!
Page 2 of 9
iNeuron Intelligence Pvt Ltd
2)Join () func3on
The join () func\on is used to return a string that has string
elements joined by a separator. The syntax for using join ()
func\on.
string_name. join (sequence)
string1 = “-“
sequence = (“1”, ”2”, “3”, “4”,)
print ([Link](sequence))
1-2-3-4
3) % operator
string1 = “Hi”
string2 = “There”
string3 = “%s %s” % (string1, string2)
print(string3)
Hi There
4) format () func3on
string1= “Hi”
string2= “There”
string3 = “{} {}”. format (string1, string2)
print(string3)
Hi There
5) f-string
string1= “Hi”
string2= “There”
string3= f’ {string1} {string2}’
print(string3)
Hi There
Page 3 of 9
iNeuron Intelligence Pvt Ltd
[Link] can you repeat strings in Python?
Ans- Strings can be repeated either using the mul\plica\on sign ‘*’ or
by using for loop.
Ø Operator for repea3ng strings
string1 = “Happy Birthday!!!”
string1*3
Happy Birthday!!! Happy Birthday!!! Happy Birthday!!!
Ø for loop for string repe33on
for x in range (0,3)
for x in range (0,3):
print (“Happy Birthday!!!)
6. What would be the output for the following lines of code?
Ans- string1 = “Happy”
string2 = “Birthday!!!”
(string1 + string2) *3
Happy Birthday!!! Happy Birthday!!! Happy Birthday!!!
7. What is the simplest way of unpacking single characters from
string “HAPPY”?
Ans- This can be doe as shown in the following code:
string1 = “Happy”
a,b,c,d,e = string1
print(a)
H
print(b)
a
print(c)
p
print(d)
Page 4 of 9
iNeuron Intelligence Pvt Ltd
p
print(e)
y
8. How can you access the fourth character of the string “HAPPY”?
Ans- You can access any character of a string by using Python’s array
like indexing syntax. The first item has an index of 0. Therefore, the
index of fourth item will be 3.
string1 = “Happy”
string1[3]
Output
p
9. If you want to start coun\ng the characters of the string from the
right most end, what index value will you use?
Ans- If the length of the string is not known we can s\ll access the
rightmost character of the string using index of -1.
string1 =” hello world”
string1[-1]
output
!
10. By mistake the programmer has created string1 having the value
“happu”. He wants to change the value of the last character. How can
that be done?
Ans- string1=” happu”
[Link](‘u’,’y’)
happy
[Link] character of the string will exist at index -2?
Page 5 of 9
iNeuron Intelligence Pvt Ltd
Ans- Index of -2 will provide second last character of the string.
string1=” happy”
string [-1]
Y
string1[-2]
p
[Link] slicing in strings.
Ans- Python allows you to extract a chunk of characters from a string
if you know the posi\on and size. All we need to do is to specify the
start and end point.
The following example shows how this can be done.
Eg-1
string1=”happy-birthday”
string1[4:7]
output
y-b
Eg-2
string1=”happy-birthday”
string1[:7]
output
happy-b
Eg-3
string1=”happy-birthday”
string1[4:]
output
y-birthday
Page 6 of 9
iNeuron Intelligence Pvt Ltd
13. What would be the output for the following code?
Ans- string1=”happy-birthday”
String1[-1: -9: -2]
Output
!!ah
14. What is the return type of func\on id?
a) int
b) float
c) bool
d) dict
Answer: a
Explana\on: Execute help(id) to find out details in python [Link]
returns a integer value that is unique.
15. What data type is the object below?
L = [1, 23, 'hello', 1]
a) list
b) dic\onary
c) array
d) tuple
Answer: a
Explana\on: List data type can store any values within it.
[Link] method to extract the last element of a list is
a) List_name[2:3]
b) List_name[-1]
c) List_name[0]
Page 7 of 9
iNeuron Intelligence Pvt Ltd
d) None of the above
Answer: a) List_name [-1]
17. To remove an element of a list, we use the arribute
a) add
b) index
c) pop
d) Delete
Answer – c) pop
18. To add an element to a list, we use the arribute
a) append
b) copy
c) reverse
d) sort
Answer- a) append
19. The process of pickling in Python includes ____________
a) conversion of a Python object hierarchy into byte stream
b) conversion of a data table into a list
c) conversion of a byte stream into Python object hierarchy
d) conversion of a list into a data table
Answer: a
Explana\on: Pickling is the process of serializing a Python object, that
is, conversion of a Python object hierarchy into a byte stream. The
reverse of this process is known as unpickling.
Page 8 of 9
iNeuron Intelligence Pvt Ltd
20. What is the return type of func\on id?
a) int
b) float
c) bool
d) dict
Answer: a
Explana\on: Execute help(id) to find out details in python [Link]
returns a integer value that is unique.
Page 9 of 9
iNeuron Intelligence Pvt Ltd
1. Which of the following results in a Syntax Error?
a) ‘” Once upon a >me…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”’
Answer: c
Explana>on: Carefully look at the colons.
[Link] a= (1,2,3,4), a [1: -1] is _________
a) Error, tuple slicing doesn’t exist
b) [2,3]
c) (2,3,4)
d) (2,3)
Answer: d
Explana>on: Tuple slicing exists and a [1: -1] returns (2,3).c) (2,3,4)
d) (2,3)
3. What type of data is: a= [(1,1), (2,4), (3,9)]?
a) Array of tuples
b) List of tuples
c) Tuples of lists
d) Invalid type
Answer: b
Explana>on: The variable a has tuples enclosed in a list making it a
list of tuples.
4. Which of these about a frozen set is not true?
a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type
Page 2 of 8
iNeuron Intelligence Pvt Ltd
Answer: a
Explana>on: A frozen set is an immutable data type.
5. Set members must not be hashable.
a) True
b) False
Answer: b
Explana>on: Set members must always be hashable.
6. Which one of these is floor division?
a) /
b) //
c) %
d) None of the men>oned
Answer: b
Explana>on: When both of the operands are integer then python
chops out the frac>on part and gives you the round off value, to get
the accurate answer use floor division.
7. Mathema>cal opera>ons can be performed on a string.
a) True
b) False
Answer: b
Explana>on: You can’t perform mathema>cal opera>on on string
even if the string is in the form: ‘1234…’.
8. Operators with the same precedence are evaluated in which
manner?
a) Lej to Right
b) Right to Lej
Page 3 of 8
iNeuron Intelligence Pvt Ltd
c) Can’t say
d) None of the men>oned
Answer: a
Explana>on: None.
8. Which one of the following has the highest precedence in the
expression?
a) Exponen>al
b) Addi>on
c) Mul>plica>on
d) Parentheses
Answer: d
Explana>on: Just remember: PEMDAS, that is, Parenthesis,
Exponen>a>on, Division, Mul>plica>on, Addi>on, Subtrac>on.
9. Which one of the following has the same precedence level?
a) Addi>on and Subtrac>on
b) Mul>plica>on, Division and Addi>on
c) Mul>plica>on, Division, Addi>on and Subtrac>on
d) Addi>on and Mul>plica>on
Answer: a
Explana>on: “Addi>on and Subtrac>on” are at the same precedence
level. Similarly, “Mul>plica>on and Division” are at the same
precedence level.
10. Operators with the same precedence are evaluated in which
manner?
a) Lej to Right
b) Right to Lej
c) Can’t say
d) None of the men>oned
Page 4 of 8
iNeuron Intelligence Pvt Ltd
Answer: a
Explana>on: None.
11. What is the default value of encoding in encode()?
a) ascii
b) qwerty
c) up-8
d) up-16
Answer: c
Explana>on: The default value of encoding is up-8.
12. Suppose list Example is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 ajer
list Example. extend([34, 5])?
a) [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
b) [1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
c) [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
d) [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
Answer: a
Explana>on: Execute in the shell to verify.
13. Suppose list Example is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 ajer
list Example. pop(1)?
a) [3, 4, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]
Answer: c
Explana>on: pop () removes the element at the posi>on specified in
the parameter.
Page 5 of 8
iNeuron Intelligence Pvt Ltd
14. Which of the following func>ons is a built-in func>on in python?
a) seed()
b) sqrt()
c) factorial()
d) print ()
Answer: d
Explana>on: The func>on seed is a func>on which is present in the
random module. The func>ons sqrt and factorial are a part of the
math module.
15. The func>on pow (x, y, z) is evaluated as:
a) (x**y) **z
b) (x**y) / z
c) (x**y) % z
d) (x**y) *z
Answer: c
Explana>on: The built-in func>on pow () can accept two or three
arguments. When it takes in two arguments, they are evaluated as
x**y.
16. Is Python case sensi>ve when dealing with iden>fiers?
a) yes
b) no
c) machine dependent
d) none of the men>oned
Answer: a
Explana>on: Case is always significant while dealing with iden>fiers in
python.
Page 6 of 8
iNeuron Intelligence Pvt Ltd
17. Which of the following statements create a dic>onary?
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:” john”, 45:” peter”}
d) All of the men>oned
Answer: d
Explana>on: Dic>onaries are created by specifying keys and values.
18. Suppose d = {“john”:40, “peter”:45}, to delete the entry for
“john” what command do we use?
a) [Link](“john”:40)
b) [Link](“john”)
c) del d[“john”]
d) del d(“john”:40)
Answer: c
Explana>on: Execute in the shell to verify.
19. Suppose d = {“john”:40, “peter”:45}. To obtain the number of
entries in dic>onary which command do we use?
a) d. size()
b) len(d)
c) size(d)
d) d. len()
Answer: b
Explana>on: Execute in the shell to verify.
20. Suppose d = {“john”:40, “peter”:45}, what happens when we try
to retrieve a value using the expression d[“susan”]?
a) Since “susan” is not a value in the set, Python raises a Key Error
excep>on
b) It is executed fine and no excep>on is raised, and it returns None
Page 7 of 8
iNeuron Intelligence Pvt Ltd
c) Since “susan” is not a key in the set, Python raises a Key Error
excep>on
d) Since “susan” is not a key in the set, Python raises a syntax error
Answer: c
Explana>on: Execute in the shell to verify.
Page 8 of 8
iNeuron Intelligence Pvt Ltd
1. Which of the statements about dic3onary values if false?
a) More than one key can have the same value
b) The values of the dic3onary can be accessed as dict[key]
c) Values of a dic3onary must be unique
d) Values of a dic3onary can be a mixture of leBers and numbers
Answer: c
Explana3on: More than one key can have the same value.
2. If a is a dic3onary with some key-value pairs, what does [Link]
item() do?
a) Removes an arbitrary element
b) Removes all the key-value pairs
c) Removes the key-value pair for the key given as an argument
d) Invalid method for dic3onary
Answer: a
Explana3on: The method pop item() removes a random key-value
pair.
3. Name the important escape sequence in Python.
Ans- Some of the important escape sequences in Python are as
follows:
• \\: Backlash
• \’: Single quote
• \”: Double quote
• \f: ASCII from feed
• \n: ASCII linefeed
• \t: ASCII tab
• \v: Ver3cal tab
Page 2 of 9
iNeuron Intelligence Pvt Ltd
4. What is a list?
Ans- A list is a in built Python data structure that can be changed. It is
an ordered sequence of elements and every element inside the list
may also be called as item. By ordered sequence, it is meant that
every element of the list that can be called individually by its index
number. The elements of a list are enclosed in square brackets [].
5. How would you access the element of the following list?
6. Concatenate the two strings.
Page 3 of 9
iNeuron Intelligence Pvt Ltd
7. What is the difference between append () and extend () func3on
for lists?
Ans- The append () func3on allows you to add one element to a list
whereas extend () allows you to add more than one element to the
list.
8. How the format method works?
Ans- The format method works by pu`ng a period directly aaer the
ending string quota3on, followed by the keyword “format”. Within
the parenthesis aaer the keyword are the variables that will be
injected into the string. No maBer what data type it is, it will insert it
into the string in the proper loca3on, which brings up the ques3on,
how does it know where to put it? That’s where the curly brackets
come in to play. The order of the curly brackets is the same order for
the variables within the format parenthesis. To include mul3ple
variables in one format string, you simply separate each by a comma.
Let’s check out some examples:
Page 4 of 9
iNeuron Intelligence Pvt Ltd
9. How the strings are stored?
Ans- When a computer saves a string into memory, each character
within the string is assigned what we call an “index.” An index is
essen3ally a loca3on in memory. Think of an index as a posi3on in a
line that you’re wai3ng in at the mall. If you were at the front of the
line, you would be given an index number of zero. The person behind
you would be given index posi3on one. The person behind them
would be given index posi3on two and so on.
Q8. Why python is an Object-Oriented programming language?
Ans- Python is an object-oriented (OO) programming language.
Unlike some other object-oriented languages, however, Python
doesn’t force you to use the object-oriented paradigm exclusively: it
also supports procedural programming, with modules and func3ons,
so that you can select the best paradigm for each part of your
program. The object-oriented paradigm helps you group state (data)
and behaviour(code) together in handy packets of func3onality.
Moreover, it offers some useful specialized mechanisms covered in
this chapter, like inheritance and special methods. The simpler
procedural approach, based on modules and func3ons, may be more
suitable when you don’t need the pluses1 of object-oriented
programming. With Python, you can mix and match paradigms.
10. What Are Python’s Technical Strengths?
Ans- Naturally, this is a developer’s ques3on. If you don’t already
have a programming background, the language in the next few
sec3ons may be a bit baffling—don’t worry, we’ll explore all of these
terms in more detail as we proceed through this book. For
developers, though, here is a quick introduc3on to some of Python’s
top technical features.
Page 5 of 9
iNeuron Intelligence Pvt Ltd
11. How Does Python Stack Up to Language X?
Ans- Finally, to place it in the context of what you may already know,
people some3mes compare Python to languages such as Perl, Tcl,
and Java. This sec3on summarizes common consensus in this
department.
I want to note up front that I’m not a fan of winning by disparaging
the compe33on—it doesn’t work in the long run, and that’s not the
goal here. Moreover, this is not a zero sum game—most
programmers will use many languages over their careers.
Nevertheless, programming tools present choices and tradeoffs that
merit considera3on. Aaer all, if Python didn’t offer something over
its alterna3ves, it would never have been used in the first place.
12. How python is a Rapid Prototyping?
Ans- To Python programs, components wriBen in Python and C look
the same. Because of this, it’s possible to prototype systems in
Python ini3ally, and then move selected components to a compiled
language such as C or C++ for delivery. Unlike some prototyping tools,
Python doesn’t require a complete rewrite once the prototype has
solidified. Parts of the system that don’t require the efficiency of a
language such as C++ can remain coded in Python for ease of
maintenance and use.
13. What is the func3on of interac3ve shell?
Ans- The interac3ve shell stands between the commands give by the
user and the execu3on done by the opera3ng system. It allows users
to use easy shell commands and the user need not be bothered
about the complicated basic func3ons of the Opera3ng System. This
also protects the opera3ng system from incorrect usage of system
func3ons.
Page 6 of 9
iNeuron Intelligence Pvt Ltd
14. What does the pop() func3on do?
Ans- The pop func3on can be used to remove an element from a
par3cular index and if no index value is provided, it will remove the
last element. The func3on returns the value of the element removed.
15. Is there any method to extend a list?
Page 7 of 9
iNeuron Intelligence Pvt Ltd
16. Is there any method to clear the contents of a list?
Ans- Contents of a list can be cleared using clear () func3on.
17. How to insert the item in a list.
Ans-
18. How to copy the elements of a list?
19. When would you prefer to use a tuple or list?
Ans-Tuples and lists can be used for similar situa3ons but tuples are
generally preferred for collec3on of heterogenous datatypes whereas
list are considered for homogeneous data types. Itera3ng through a
tuple is faster than itera3ng through list. Tuples are idle for storing
values that you don’t want to change. Since Tuples are immutable,
the values within are write-protected.
Page 8 of 9
iNeuron Intelligence Pvt Ltd
20. How can you create a tuple?
Page 9 of 9
iNeuron Intelligence Pvt Ltd
1. Present different types of tuples.
2. How to access Python Tuple Elements
Ans- We can use the index operator [] to access an item in a tuple,
where the index starts from 0.
So, a tuple having 6 elements will have indices from 0 to 5. Trying to
access an index outside of the tuple index range (6, 7, ... in this
example) will raise an Index Error.
The index must be an integer, so we cannot use float or other types.
This will result in Type Error.
Likewise, nested tuples are accessed using nested indexing, as shown
in the example below.
Page 2 of 8
iNeuron Intelligence Pvt Ltd
3. How to use negaNve indexing in tuple?
Ans- Python allows negaNve indexing for its sequences.
The index of -1 refers to the last item, -2 to the second last item and
so on. For example,
[Link] of slicing in tuple.
Ans- We can access a range of items in a tuple by using the slicing
operator colon:
5. Which of the following is invalid variable?
a) string_123
b) _hello
Page 3 of 8
iNeuron Intelligence Pvt Ltd
c) 12_hello
d) None of these
Answer – c) 12_hello
6. Is python idenNfiers case sensiNve?
a) False
b) True
c) Depends on program
d) Depends on computer
Answer – b) True
7. Which of the following statements is true regarding Python?
a) Python does not support object-oriented programming.
b) Python uses indentaNon to indicate block structure.
c) Python is a compiled language.
d) Python is a staNcally typed language.
Answer – b) uses indentaNon to indicate block structure.
8. List in Python is ................in nature.
a) funcNonable
b) mutable
c) immutable
d) None of these
Answer- b) mutable
9. Which of the following is NOT a valid type code for Python array?
a) 'i'
b) 'f'
Page 4 of 8
iNeuron Intelligence Pvt Ltd
c) 'd'
d) 's'
Answer – d) 's'
10. What is the output of the following Python code?
import array
a = [Link]('i', [1, 2, 3])
print(a[0])
a) 0
b) 2
c) 1
d) 3
Answer – c) 1
11. When was Python 3.0 released?
a. 3 December 2008
b. 4 December 2008
c. 5 December 2008
d. 3 December 2010
Answer- 1. The new version of Python 3.0 was released on December
3, 2008.
12. Who founded Python?
a. Alexander G. Bell
b. Vincent van Gogh
c. Leonardo da Vinci
d. Guido van Rossum
Answer. d. The idea of Python was conceived by Guido van Rossum in
the later 1980s.
Page 5 of 8
iNeuron Intelligence Pvt Ltd
13. What are the people who specialize in Python called?
a. Pythonic
b. Unpythonic
c. Monty Python
d. Pythonistas
Answer. d. the people who specialize, or are great admirers of this
programming language are called as Pythonistas. They are extremely
knowledgeable people.
14. What is the type of programming language supported by Python?
a. Object-oriented
b. FuncNonal programming
c. Structured programming
d. All of the above
Answer. d. Python is an interpreted programming language,
supporNng object-oriented, structured, and funcNonal programming.
15. All the keywords in Python are in_
a. Lower case
b. Upper case
c. Capitalized
d. None of the above
Answer. d. Only True, False and None are capitalized and all the
others in lower case.
16. What is the order in which namespaces in Python looks for an
idenNfier?
a. First, the python searches for the built-in namespace, then the
global namespace and then the local namespace
Page 6 of 8
iNeuron Intelligence Pvt Ltd
b. Python first searches for the built-in namespace, then local and
finally the global namespace
c. Python first searches for local namespace, then global
namespace and finally the built-in namespace
d. Python searches for the global namespace, followed by the
local namespace and finally the built-in namespace.
Answer. C. Python first searches for the local namespace, followed by
the global and finally the built-in namespace.
17. What is Python code-compiled or interpreted?
a. The code is both compiled and interpreted
b. Neither compiled nor interpreted
c. Only compiled
d. Only interpreted
Answer. b. There are a lot of languages which have been
implemented using both compilers and interpreters, including C,
Pascal, as well as python.
18. What is the funcNon of pickling in python?
a. Conversion of a python object
b. Conversion of database into list
c. Conversion of byte stream into python object hierarchy
d. Conversion of list into database
Answer. a. The process of pickling refers to sterilizing a Python object,
which means converNng a byte stream into python object hierarchy.
The process which is the opposite of pickling is called unpickling.
Page 7 of 8
iNeuron Intelligence Pvt Ltd
19. How to create a python tuple index?
[Link] are the numeric data types in python?
Ans- In Python, numeric data type is used to hold numeric values.
Integers, floaNng-point numbers and complex numbers fall under
Python numbers category. They are defined as int, float and complex
classes in Python.
• int - holds signed integers of non-limited length.
• float - holds floaNng decimal points and it's accurate up to 15
decimal places.
• complex - holds complex numbers.
Page 8 of 8
iNeuron Intelligence Pvt Ltd
1. Suppose there are two sets, set1 and set2, where set1 is the
superset of set2. It is required to get only the unique elements of
both the sets. Which of the following will serve the purpose?
set1= {2,3}
set2= {3,2}
set3= {2,1}
if(set1==set2):
print("yes")
else:
print("no")
if(set1==set3):
print("yes")
else:
print("no")
A. set1|set2
B. set1&set2
C. set1-set2
D. None of the above
Ans: C
ExplanaRon: set1-set2 will serve the purpose.
Page 2 of 10
iNeuron Intelligence Pvt Ltd
2. The elements of a list are arranged in descending order. Which of
the following two will give same outputs?
i. print(list_name.sort())
ii. print(max(list_name))
iii. print(list_name.reverse())
iv. print(list_name[-1])
A. i, ii
B. i, iii
C. ii, iii
D. iii, iv
Ans: B
ExplanaRon: print(list_name. sort ()) and print(list_name.reverse())
will give same outputs.
3. What will be the output of below Python code?
list1=[1,3,5,2,4,6,2]
[Link](2)
print(sum(list1))
A. 18
B. 19
C. 21
D. 22
Ans: C
ExplanaRon: 21 will be the result a]er the execuRon of above Python
code.
4. Which of the following would give an error?
Page 3 of 10
iNeuron Intelligence Pvt Ltd
A. list1 = []
B. list1= [] *3
C. list1= [2,8,7]
D. None of the above
Ans: D
ExplanaRon: None of the above will result in error
5. What is type conversion in python?
Ans - When we perform any operaRon on variables of different
datatypes, the data of one variable will be converted to a higher
datatype among the two variables and the operaRon is completed.
When this conversion is done by interpreter automaRcally then it is
known as implicit type conversion while conversions is done by user
then it is called explicit type conversion.
num1=10
num2="20"
result=num1+int(num2)
print(result)
6. When we want to treat some data as a group, it would not be good
to create individual variables for each data. We can store them
together as a collecRon.
Ans- There are many collecRon data types which are supported by
Python-
1. List- List can be used to store a group of elements together in a
sequence.
Page 4 of 10
iNeuron Intelligence Pvt Ltd
2. Tuple- A tuple is an immutable sequence of Python objects. Tuples
are sequences, just like lists.
3. String- In a program, not all values will be numerical. We will also
have alphabeRcal or alpha numerical values. Such values are called
strings.
4. Set- A set is an unordered group of values with no duplicate
entries. Set can be created by using the keyword set or by using curly
braces {}. set funcRon is used to eliminate duplicate values in a list.
5. DicRonary- A dicRonary can be used to store an unordered
collecRon of key-value pairs. The key should be unique and can be of
any data type. Like lists, dicRonaries are mutable.
7. What is math module?
Answer - math is another useful module in Python. Once you have
imported the math module, you can use some of the below
funcRons:
1. math. ceil(x) - Smallest integer greater than or equal to x
2. math. floor(x) - Largest integer smaller than or equal to x
3. [Link](x) - Factorial of x
4. math. fabs(x) - Gives absolute value of x
8. What are the differences between python 2 and 3?
Answer -The main differences between python 2 and python 3 are as
follows -
python 2 python 3
a) print statement is treated print statement is treated more
more as statement as statement
b) integer size limited to 32 bits integer size unlimited
Page 5 of 10
iNeuron Intelligence Pvt Ltd
c) complex Simplified
d) ASCII is used. Unicode is used.
9. What are docstrings in Python?
Answer - Docstrings are not actually comments, but they are
documentaRon strings. These docstrings are within triple quotes.
They are not assigned to any variable and therefore, at Rmes, serve
the purpose of comments as well.
"""
Using docstring as a comment.
This code divides 2 numbers
"""
a=10
b=5
c=a/b
print(c)
Output -
2.0
10. What is __init__ in Python?
Answer - "__init__" is a reserved method in python classes. It is
called as a constructor in object-oriented terminology. This method
is called when an object is created from a class and it allows the
class to iniRalize the anributes of the class.
11. Does Python have Opp’s concepts?
Ans - Python is an object-oriented programming language. This
means that any program can be solved in python by creaRng an
Page 6 of 10
iNeuron Intelligence Pvt Ltd
object model. However, Python can be treated as procedural as well
as structural language.
12. How will you capitalize the first lener of string?
Ans- In Python, the capitalize () method capitalizes the first lener of a
string. If the string already consists of a capital lener at the
beginning, then, it returns the original string.
13. Why we use Lambda FuncRons?
Ans - Lambda funcRons are used when you need a funcRon for a
short period of Rme. This is commonly used when you want to pass a
funcRon as an argument to higher-order funcRons, i.e. funcRons that
take other funcRons as their arguments.
14. What is ExcepRon handling in python?
Ans - SomeRmes the programs may misbehave or terminate/crash
unexpectedly due to some unexpected events during the execuRon
of a program. These unexpected events are called as excepRons and
the process of handling them to avoid misbehaviour or crashing the
program is called as excepRon handling.
15. What are funcRons in python?
Ans - FuncRons are set of instrucRons to perform a specific task.
Below is the syntax of funcRons in python.
def funcRon_name ([arg1, ..., argn]):
#statements
[return value]
variable_name = funcRon_name ([val1, ..., valn])
Page 7 of 10
iNeuron Intelligence Pvt Ltd
16. How many types of arguments are there in python?
Ans- Programming languages allow controlling the ordering and
default values of arguments.
1. PosiRonal Default way of specifying arguments. In this, the order,
count and type of actual argument should exactly match to that of
formal argument. Else, it will result in error.
def funcRon_name (arg1, arg2):
#statements
return result
res = funcRon_name (val1, val2)
2. Keyword: Allow flexibility in order of passing actual arguments by
menRoning the argument name.
def funcRon_name (arg1, arg2):
#statements
return result
res = funcRon_name (arg2=val2, arg1=val1)
3. Default: Allow to specify the default value for an argument in the
funcRon signature. It is used only when no value is passed for that
argument else it works normally. In python default arguments should
be last in order.
def funcRon_name (arg1, arg2=default value):
#statements
return result
Page 8 of 10
iNeuron Intelligence Pvt Ltd
res = funcRon_name(val1)
4. Variable argument count: Allow funcRon to have variable number
of arguments. In python, any argument name starRng with '*' is
consider to be vary length argument. It should be last in order. It will
copy all values beyond that posiRon into a tuple.
def funcRon_name (arg1, arg2, *arg3):
#statements
return result
res = funcRon_name (val1, val2, val3, val4, val5)
17. What is random module?
Answer -Python has many inbuilt packages and modules. One of the
most useful modules is random. This module helps in generaRng
random numbers.
The code given below generates a random number between x and y-
1 (both inclusive) using the randrange funcRon of the random
module.
import random
a=20
b=30
print(random. randrange (a, b))
output:
Any random number between 20 to 30.
Page 9 of 10
iNeuron Intelligence Pvt Ltd
18. What is seek() funcRon in python?
Answer - Python provides seek() funcRon to navigate the file object
pointer to the required posiRon specified.
Syntax: file_object. seek(offset, [whence])
//file_object indicates the file object pointer to be navigated
//offset indicates which posiRon the file object pointer is to be
navigated
19. What is PEP 8??
Ans- PEP 8 is a coding convenRon, a set of recommendaRons, about
how to write your Python code more readable.
20. What is pickling and unpickling in Python?
Ans- Pickling is a way to convert a python object (list, dict, etc.) into a
character stream. Pickle has two main methods. The first one is
dump, which dumps an object to a file object and the second one is
load, which loads an object from a file object.
While the process of retrieving original Python objects from the
stored string representaRon is called unpickling.
Page 10 of 10
iNeuron Intelligence Pvt Ltd
1. What is namespace in Python?
Ans- In Python, every name introduced has a place where it lives and
can be hooked for. This is known as namespace. It is like a box where
a variable name is mapped to the object placed. Whenever the
variable is searched out, this box will be searched, to get
corresponding object.
2. What is difference between range and xrange?
Ans- The differences between range and xrange are as follows –
Range Xrange
a) Access via list method Access via index
b) slower for larger range Faster
c) python 2 and python 3 python 2 and python 3
3. Which of the following funcJon is used to know the data type of a
variable in Python?
A. datatype ()
B. typeof()
C. type()
D. vartype()
View Answer
Ans: C
ExplanaJon: type() funcJon is used to know the data type of a
variable in Python. So,opJon C is correct.
Page 2 of 10
iNeuron Intelligence Pvt Ltd
4. What is the output of following: set([1,1,2,3,4,2,3,4])
A. [1,1,2,3,4,2,3,4]
B. {1,2,3,4}
C. {1,1,2,3,4,2,3,4}
D. Invalid Syntax
Ans- B
ExplanaJon: Set will remove the duplicate values from the list. So,
OpJon B is correct.
5. Which of the following statements is used to create an empty set?
A. []
B. {}
C. ()
D. set()
Ans: D
ExplanaJon: set() is used to create an empty set. So, OpJon D is
correct.
6. Which one of the following is mutable data type?
A. set
B. int
C. str
D. tuple
View Answer
Ans: A
Page 3 of 10
iNeuron Intelligence Pvt Ltd
ExplanaJon: set is one of the following is mutable data type. So,
opJon A is correct.
7. Which one of the following is immutable data type?
A. list
B. set
C. int
D. dict
View Answer
Ans: C
ExplanaJon: int one of the following is immutable data type. So,
OpJon C is correct.
Q49. How to get last element of list in python? Suppose we have list
with name arr, contains 5 elements.
A. arr[0]
B. arr[5]
C. arr[last]
D. arr[-1]
Ans: D
ExplanaJon: The arr[-n] syntax gets the nth-to-last element. So arr[-
1] gets the last element, arr[-2] gets the second to last, etc. So,
OpJon D is correct.
8. How to copy one list to another in python?
A. l1[] = l2[]
B. l1[] = l2
Page 4 of 10
iNeuron Intelligence Pvt Ltd
C. l1[] = l2[:]
D. l1 = l2
View Answer
Ans- C
ExplanaJon: OpJon A and B syntax is incorrect while D will point
both name to same list. Hence C is the best way to copy the one list
to another. So, OpJon C is correct.
9. Suppose a tuple arr contains 10 elements. How can you set the 5th
element of the tuple to 'Hello'?
A. arr[4] = 'Hello'
B. arr(4) = 'Hello'
C. arr[5] = 'Hello'
D. Elements of tuple cannot be changed
Ans: D
ExplanaJon: Tuples are immutable that is the value cannot be
changed. So, OpJon D is correct.
10. Which of the following creates a tuple?
A. tuple1= ("a", "b")
B. tuple1[2] = ("a”, ”b")
C. tuple1= (5) *2
D. None of the above
Ans: A
ExplanaJon: We can create a tuple using tuple1= ("a", "b").
11. Choose the correct opJon with respect to Python.
Page 5 of 10
iNeuron Intelligence Pvt Ltd
A. Both tuples and lists are immutable.
B. Tuples are immutable while lists are mutable.
C. Both tuples and lists are mutable.
D. Tuples are mutable while lists are immutable.
View Answer
Ans- B
ExplanaJon: Tuples are immutable while lists are mutable the correct
opJon with respect to Python.
12. What will be the output of below Python code?
tuple1= (5,1,7,6,2)
[Link](2)
print(tuple1)
A. (5,1,6,2)
B. (5,1,7,6)
C. (5,1,7,6,2)
D. Error
Ans- D
ExplanaJon: The following code will result in error.
13. What will be the output of below Python code?
tuple1= (2,4,3)
tuple3=tuple1*2
Page 6 of 10
iNeuron Intelligence Pvt Ltd
print(tuple3)
A. (4,8,6)
B. (2,4,3,2,4,3)
C. (2,2,4,4,3,3)
D. Error
Ans- B
ExplanaJon: The following code will result in (2,4,3,2,4,3).
14. What will be the output of below Python code?
tupl=([2,3],"abc",0,9)
tupl [0][1] =1
print(tupl)
A. ([2,3],"abc",0,9)
B. ([1,3],"abc",0,9)
C. ([2,1],"abc",0,9)
D. Error
Ans: C
ExplanaJon: The output for the following code is ([2,1],"abc",0,9).
15. What will be the output of the following Python code?
def fn(var1):
[Link](1)
var1= [1,2,3]
fn(var1)
print(var1)
Page 7 of 10
iNeuron Intelligence Pvt Ltd
A. [1,2,3]
B. [1,3]
C. [2,3]
D. [1,2]
View Answer
Ans- B
ExplanaJon: [1,3] will be the output of the following Python code.
16. def funcJon1(var1):
var1=var1+10
print (var1)
var1=12
funcJon1(var1)
print(var1)
A. 22
22
B. 12
12
C. 22
22
D. 12
22
Ans- C
ExplanaJon: 22
Page 8 of 10
iNeuron Intelligence Pvt Ltd
17. What will be the output of the following Python code?
def funcJon1(var1=5, var2=7):
var2=9
var1=3
print (var1, " ", var2)
funcJon1(10,12)
A. 5 7
B. 3 9
C. 10 12
D. Error
Ans- B
ExplanaJon: 3 9 will be the output of the following Python code.
18. Which among the following are mutable objects in Python?
(i) List
(ii) Integer
(iii) String
(iv) Tuple
A. i only
B. i and ii only
C. iii and iv only
D. iv only
Ans- A
ExplanaJon: List are mutable objects in Python.
[Link] to Check Whether a Number is Even or Odd.
Page 9 of 10
iNeuron Intelligence Pvt Ltd
20. How to check Whether a Number is Prime or not.
Page 10 of 10
iNeuron Intelligence Pvt Ltd
1. Which of the following is not used as loop in Python?
A. for loop
B. while loop
C. do-while loop
D. None of the above
Ans: C
ExplanaDon: do-while loop is not used as loop in Python.
2. Which of the following is False regarding loops in Python?
A. Loops are used to perform certain tasks repeatedly.
B. While loop is used when mulDple statements are to executed
repeatedly unDl the given condiDon becomes False
C. While loop is used when mulDple statements are to executed
repeatedly unDl the given condiDon becomes True.
D. for loop can be used to iterate through the elements of lists.
Ans: B
ExplanaDon: While loop is used when mulDple statements are to
executed repeatedly unDl the given condiDon becomes False
statement is False regarding loops in Python.
3. What will be the output of given Python code?
n=7
c=0
while(n):
Page 2 of 11
iNeuron Intelligence Pvt Ltd
if(n>5):
c=c+n-1
n=n-1
else:
break
print(n)
print(c)
A. 5 11
B. 5 9
C. 7 11
D. 5 2
Ans: A
ExplanaDon: 5 11 will be the output of the given code
4. What will be the output of the following Python code?
for i in range(0,2,-1):
print("Hello")
A. Hello
B. Hello Hello
Page 3 of 11
iNeuron Intelligence Pvt Ltd
C. No Output
D. Error
View Answer
Ans: C
ExplanaDon: There will be no output of the following python code.
5. What keyword would you use to add an alternaDve condiDon to an
if statement?
A. else if
B. elseif
C. elif
D. None of the above
View Answer
Ans : C
ExplanaDon: elif is used to add an alternaDve condiDon to an if
statement. So, opDon C is correct.
6. Can we write if/else into one line in python?
A. Yes
B. No
C. if/else not used in python
D. None of the above
View Answer
Ans : A
Page 4 of 11
iNeuron Intelligence Pvt Ltd
ExplanaDon: Yes, we can write if/else in one line. For eg i = 5 if a > 7
else 0. So, opDon A is correct.
7. What will be output of this expression:
'p' + 'q' if '12'.isdigit() else 'r' + 's'
A. pq
B. rs
C. pqrs
D. pq12
View Answer
Ans: A
Explanation: If condition is true so pq will be the output. So, option A
is correct.
8. Which statement will check if a is equal to b?
A. if a = b:
B. if a == b:
C. if a === c:
D. if a == b
View Answer
Ans: B
Explanation: if a == b: statement will check if a is equal to b. So,
option B is correct.
9. A while loop in Python is used for what type of iteraDon?
A. indefinite
B. discriminant
Page 5 of 11
iNeuron Intelligence Pvt Ltd
C. definite
D. indeterminate
Ans: A
ExplanaDon: A while loop implements indefinite iteraDon, where the
number of Dmes the loop will be executed is not specified explicitly
in advance. So, opDon A is correct.
10. When does the else statement wri`en aaer loop executes?
A. When break statement is executed in the loop
B. When loop condiDon becomes false
C. Else statement is always executed
D. None of the above
Ans: B
ExplanaDon: Else statement aaer loop will be executed only when
the loop condiDon becomes false. So, opDon B is correct.
11. A loop becomes infinite loop if a condition never becomes
________.
A. TRUE
B. FALSE
C. Null
D. Both A and C
Page 6 of 11
iNeuron Intelligence Pvt Ltd
View Answer
Ans: B
Explanation: A loop becomes infinite loop if a condition never
becomes FALSE. You must use caution when using while loops
because of the possibility that this condition never resolves to a
FALSE value. This results in a loop that never ends. Such a loop is
called an infinite loop.
12. If the else statement is used with a while loop, the else statement
is executed when the condition becomes _______.
A. TRUE
B. FALSE
C. Infinite
D. Null
Ans: B
Explanation: If the else statement is used with a while loop, the else
statement is executed when the condition becomes false.
13. The ________ statement is a null operation.
Page 7 of 11
iNeuron Intelligence Pvt Ltd
A. break
B. exit
C. return
D. pass
Ans: D
Explanation: The pass statement is a null operation; nothing happens
when it executes.
14. The continue statement can be used in?
A. while loop
B. for loop
C. do-while
D. Both A and B
Ans: D
Explanation: The continue statement can be used in both while and
for loops.
15. Which of the following is a valid for loop in Python?
A. for(i=0; i < n; i++)
B. for i in range(0,5):
C. for i in range(0,5)
D. for i in range(5)
View Answer
Ans: B
Page 8 of 11
iNeuron Intelligence Pvt Ltd
ExplanaDon: For statement always ended with colon (:). So, opDon B
is correct.
16. Which of the following sequences would be generated bt the
given line of code?
range (5, 0, -2)
A. 5 4 3 2 1 0 -1
B. 5 4 3 2 1 0
C. 5 3 1
D. None of the above
View Answer
Ans: C
ExplanaDon: The iniDal value is 5 which is decreased by 2 Dll 0 so we
get 5, then 2 is decreased so we get 3 then the same thing repeated
we get 1 and now when 2 is decreased we get -1 which is less than 0
so we stop and hence we get 5 3 1. So, opDon C is correct.
17. When does the else statement wri`en aaer loop executes?
A. When break statement is executed in the loop
B. When loop condiDon becomes false
C. Else statement is always executed
D. None of the above
Ans: B
ExplanaDon: Else statement aaer loop will be executed only when
the loop condiDon becomes false. So, opDon B is correct.
Page 9 of 11
iNeuron Intelligence Pvt Ltd
18. The ________ statement is a null operaDon.
A. break
B. exit
C. return
D. pass
View Answer
Ans: D
ExplanaDon: The pass statement is a null operaDon; nothing happens
when it executes.
19. The conDnue statement can be used in?
A. while loop
B. for loop
C. do-while
D. Both A and B
View Answer
Ans: D
ExplanaDon: The conDnue statement can be used in both while and
for loops
20. What will be the output of the following Python code?
list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
sum = 0
Page 10 of 11
iNeuron Intelligence Pvt Ltd
sum1 = 0
for elem in list1:
if (elem % 2 == 0):
sum = sum + elem
conDnue
if (elem % 3 == 0):
sum1 = sum1 + elem
print(sum , end=" ")
print(sum1)
A. 8 9
B. 8 3
C. 2 3
D. 8 12
View Answer
Ans- D
ExplanaDon: The output of the following python code is 8 12.
Page 11 of 11
iNeuron Intelligence Pvt Ltd
1. How to Check whether the Given Year is Leap Year or Not.
Ans-
2. Write a python program to Print Fibonacci Series.
3. Write a Python Program to Check Vowel or Consonant.
Page 2 of 11
iNeuron Intelligence Pvt Ltd
4. Which statement is correct?
A. List is immutable && Tuple is mutable
B. List is mutable && Tuple is immutable
C. Both are Mutable.
D. Both are Immutable
Ans : B
ExplanaRon: List is mutable and Tuple is immutable. A mutable data
type means that a python object of this type can be modified. An
immutable object can't. So, OpRon B is correct.
5. To create a class, use the keyword?
A. new
B. except
C. class
D. object
Ans: C
ExplanaRon: To create a class, use the keyword class
Page 3 of 11
iNeuron Intelligence Pvt Ltd
6. All classes have a funcRon called?
A. __init__
B. __init__()
C. init
D. init()
Ans: B
ExplanaRon: All classes have a funcRon called __init__(), which is
always executed when the class is being iniRated.
7. The __________ parameter is a reference to the current instance
of the class, and is used to access variables that belong to the class.
A. __init__()
B. self
C. both A and B
D. None of the above
Ans: B
ExplanaRon: The self-parameter is a reference to the current instance
of the class, and is used to access variables that belong to the class.
8. You can delete properRes on objects by using the ______ keyword.
A. delete
B. dedl
Page 4 of 11
iNeuron Intelligence Pvt Ltd
C. del
D. drop
Ans: C
ExplanaRon: You can delete properRes on objects by using the del
keyword
9. A variable that is defined inside a method and belongs only to the
current instance of a class is known as?
A. Inheritance
B. Instance variable
C. FuncRon overloading
D. InstanRaRon
Ans: B
ExplanaRon: Instance variable: A variable that is defined inside a
method and belongs only to the current instance of a class.
10. A class variable or instance variable that holds data associated
with a class and its object is known as?
A. Class variable
B. Method
C. Operator overloading
D. Data member
Page 5 of 11
iNeuron Intelligence Pvt Ltd
Ans: D
ExplanaRon: Data member: A class variable or instance variable that
holds data associated with a class and its objects.
11. What is setacr() used for?
A. To set an acribute
B. To access the acribute of the object
C. To check if an acribute exists or not
D. To delete an acribute
Ans: A
ExplanaRon: setacr (obj, name, value) is used to set an acribute. If
acribute doesn’t exist, then it would be created.
12. What will be output for the following code?
class test:
def __init__(self,a):
self.a=a
def display(self):
print(self.a)
obj= test ()
obj. display ()
Page 6 of 11
iNeuron Intelligence Pvt Ltd
A. Runs normally, doesn’t display anything
B. Displays 0, which is the automaRc default value
C. Error as one argument is required while creaRng the object
D. Error as display funcRon requires addiRonal argument
Ans: C
ExplanaRon: Since, the __init__ special method has another
argument a other than self, during object creaRon, one argument is
required. For example: obj=test(“Hello”)
13. ___ represents an enRty in the real world with its idenRty and
behaviour.
A. A method
B. An object
C. A class
D. An operator
View Answer
Ans- B
ExplanaRon: An object represents an enRty in the real world that can
be disRnctly idenRfied. A class may define an object.
14. Which of the following is correct with respect to OOP concept in
Python?
Page 7 of 11
iNeuron Intelligence Pvt Ltd
A. Objects are real world enRRes while classes are not real.
B. Classes are real world enRRes while objects are not real.
C. Both objects and classes are real world enRRes.
D. Both object and classes are not real.
Ans: A
ExplanaRon: In OOP, classes are basically the blueprint of the objects.
They does not have physical existence.
15. In python, what is method inside class?
A. acribute
B. object
C. argument
D. funcRon
Ans: D
ExplanaRon: In OOP of Python, funcRon is known by "method".
16. Which one of the following is correct?
A. In python, a dicRonary can have two same keys with different
values.
B. In python, a dicRonary can have two same values with different
keys
C. In python, a dicRonary can have two same keys or same values
but cannot have two same key-value pair
D. In python, a dicRonary can neither have two same keys nor two
same values.
Page 8 of 11
iNeuron Intelligence Pvt Ltd
Ans: B
ExplanaRon: In python, a dicRonary can have two same values with
different keys.
17. What will be the following Python code?
dict1={"a":10,"b":2,"c":3}
str1=""
for i in dict1:
str1=str1+str(dict1[i])+" "
str2=str1[:-1]
print(str2[::-1])
A. 3, 2
B. 3, 2, 10
C. 3, 2, 01
D. Error
Ans: C
ExplanaRon: 3, 2, 01 will be the following Python code output.
Page 9 of 11
iNeuron Intelligence Pvt Ltd
18. Write a Python Program to Find Factorial of a Number.
19. What are operators?
Ans-Operators are required to perform various operaRons on data.
They are special symbols that are required to carry out arithmeRc
and logical operaRons. The values on which the operator operates
are called operands.
So, if we say 10/5=2
Here ‘/’ is the operator that performs division and 10 and 5 are the
operands. Python has following operators defined for various
operaRons:
a) ArithmeRc Operators
b) RelaRonal Operators
c) Logical Operators
d)Assignment Operators
e) Bitwise Operators
f) Membership Operators
g) IdenRty Operators
20. What are ArithmeRc operators? What are various types of
arithmeRc operators that we can use in python?
Page 10 of 11
iNeuron Intelligence Pvt Ltd
Ans- They are used to perform mathemaRcal funcRons such as
addiRon, subtracRon, division, and mulRplicaRon. Various types of
arithmeRc operators that we can use in Python are as follows:
Page 11 of 11
iNeuron Intelligence Pvt Ltd
1. What is the Arithme.c operators precedence in Python?
Ans- When more than one arithme.c operator appears in an expression the
[Link] will execute in a specific order. In Python the [Link] precedence
follows as per the acronym PEMDAS.
Parenthesis
Exponent
[Link]
[Link]
Division
[Link]
Q4. Evaluate the following keeping Python’s precedence of operators.
a=2
b=4
c=5
d=4
print(a+b+c)
print(a+b*c+d)
print(a/b+c/d)
print(a+b*c+a/b+d)
Ans-
2. What are [Link] operators?
Ans- [Link] operators are known as [Link] operators.
Page 2 of 9
iNeuron Intelligence Pvt Ltd
Equal
x=y
True if x is equal to y.
>
Greater than
x>y
True if x is greater than y.
<
Less than
x<y
True if x is less than y.
>=
Greater than or equal to
x >= y
True if x is greater than or equal to y.
<=
Less than or equal to
Page 3 of 9
iNeuron Intelligence Pvt Ltd
x <= y
True if x is less than or equal to y.
!=
Not equal to
x != y
True if x is not equal to y.
3. a = 5, b = 6, c = 7, d = 7
What will be the outcome for the following:
1. a <=b>=c
2. -a+b==c>d
3. b+c==6+d>=13
Ans-
4. What is the [Link] of pickling in python?
a. Conversion of a python object
b. Conversion of database into list
c. Conversion of byte stream into python object hierarchy
Page 4 of 9
iNeuron Intelligence Pvt Ltd
d. Conversion of list into database
Answer. a. The process of pickling refers to sterilizing a Python object, which
means [Link] a byte stream into python object hierarchy. The process
which is the opposite of pickling is called unpickling.
5. What is Python code-compiled or interpreted?
a. The code is both compiled and interpreted
b. Neither compiled nor interpreted
c. Only compiled
d. Only interpreted
Answer. b. There are a lot of languages which have been implemented using
both compilers and interpreters, including C, Pascal, as well as python.
6. When was Python released?
1. 16 October, 2001
2. 16 October 2000
3. 17 October 2000
4. 17 October 2001
Answer. b. 16 October 2000. The idea of Python was conceived in the later
1980s, but it was released on a. 16 October 2000.
7. When was Python 3.0 released?
1. 3 December 2008
2. 4 December 2008
3. 5 December 2008
4. 3 December 2010
Answer. a. The new version of Python 3.0 was released on December 3, 2008.
Page 5 of 9
iNeuron Intelligence Pvt Ltd
8. Who founded Python?
1. Alexander G. Bell
2. Vincent van Gogh
3. Leonardo da Vinci
4. Guido van Rossum
Answer. d. The idea of Python was conceived by Guido van Rossum in the later
1980s.
9. What is Python?
1. A programming language
2. Computer language
3. Binary language
4. None of the above
Answer. a. Python is a programming language, basically a very high-level and a
general-purpose language.
10. What are the people who specialize in Python called?
1. Pythonic
2. Unpythonic
3. Monty Python
4. Pythoniasts
Answer. d. the people who specialize, or are great admirers of this
programming language are called as Pythoniasts. They are extremely
knowledgeable people.
11. What is the type of programming language supported by Python?
1. Object-oriented
2. [Link] programming
3. Structured programming
4. All of the above
Page 6 of 9
iNeuron Intelligence Pvt Ltd
Answer. d. Python is an interpreted programming language, [Link] object-
oriented, structured, and [Link] programming.
12. When Python is dealing with iden.fiers, is it case [Link]?
1. Yes
2. No
3. Machine dependent
4. Can’t say
Answer. a. It is case [Link].
13. What is the extension of the Python file?
1. .pl
2. .py
3. .python
4. .p
Answer. b. The correct extension of python is .py and can be wrilen in any text
editor. We need to use the extension .py to save these files.
14. All the keywords in Python are in_
1. Lower case
2. Upper case
3. Capitalized
4. None of the above
Answer. d. Only True, False and None are capitalized and all the others in lower
case.
15. What does pip mean in Python?
1. Unlimited length
2. All private members must have leading and trailing underscores
Page 7 of 9
iNeuron Intelligence Pvt Ltd
3. Preferred Installer Program
4. None of the above
Answer. c. Variable names can be of any length.
16. The built-in [Link] in Python is:
1. Print ()
2. Seed ()
3. Sqrt ()
4. Factorial ()
Answer. a. The [Link] seed is a [Link] which is present in the random
module. The [Link] sqrt and factorial are a part of the math module. The
print [Link] is a built-in [Link] which prints a value directly to the system
output.
17. Which of the following defi[Link] is the one for packages in Python?
1. A set of main modules
2. A folder of python modules
3. Set of programs making use of python modules
4. Number of files containing python defi[Link] and statements
Answer. b. A folder of python modules is called as package of modules.
18. What is the order in which namespaces in Python looks for an iden.fier?
1. First, the python searches for the built-in namespace, then the global
namespace and then the local namespace
2. Python first searches for the built-in namespace, then local and finally
the global namespace
3. Python first searches for local namespace, then global namespace and
finally the built-in namespace
Page 8 of 9
iNeuron Intelligence Pvt Ltd
4. Python searches for the global namespace, followed by the local
namespace and finally the built-in namespace.
Answer. C. Python first searches for the local namespace, followed by the
global and finally the built-in namespace.
19. Which of the following is not a keyword used in Python language?
1. Pass
2. Eval
3. Assert
4. Nonlocal
Answer. b. Eval is used as a variable in Python.
20. Which of the following is the use of func3on in python?
1. Func3ons do not provide be=er modularity for applica3ons
2. One can’t create our own func3ons
3. Func3ons are reusable pieces of programs
4. All of the above
Answer. c. Func3ons are reusable pieces of programs, which allow us
to give a name to a par3cular block of statements, allowing us to run
the block using the specified name anywhere in our program and any
number of 3mes.
Page 9 of 9
iNeuron Intelligence Pvt Ltd
1. Which of the following is a feature of Python Docstring?
1. All functions should have a docstring in python
2. Docstrings can be accessed by the _doc_ attribute on objects
3. This feature provides a very convenient way of associating
documentation with python modules, functions, classes and
methods
4. All of the above
Answer. d. Python has a nifty feature, which is referred to as the
documentation strings, usually referred to by its abbreviated name of
docstrings. They are important tools and one must use them as they
help document the program better along with making it easier to
understand.
2. Amongst which of the following is / are the Numeric Types of Data
Types?
A. int
B. float
C. complex
D. All of the mentioned above
Answer: D) All of the mentioned above
Explanation:
Numeric data types include int, float, and complex, among others. In
information technology, data types are the classification or
categorization of knowledge items. It represents the type of
information that is useful in determining what operations are
frequently performed on specific data.
Page 2 of 13
iNeuron Intelligence Pvt Ltd
3. list, tuple, and range are the ___ of Data Types.
A. Sequence Types
B. Binary Types
C. Boolean Types
D. None of the mentioned above
Answer: A) Sequence Types
Explanation:
The sequence Types of Data Types are the list, the tuple, and the
range. In order to store multiple values in an organized and efficient
manner, we use the concept of sequences.
4. Float type of data type is represented by the float class.
A. True
B. False
Answer: A) True
Explanation:
The float data type is represented by the float class of data types. A
true number with a floating-point representation is represented by
the symbol.
5. Binary data type is a fixed-width string of length bytes?
Page 3 of 13
iNeuron Intelligence Pvt Ltd
A. True
B. False
Answer: A) True
Explanation:
It is a fixed-width string of length bytes, where the length bytes is
declared as an optional specifier to the type, and its width is declared
as an integer.
6. Var binary data type returns variable-width string up to a length of
max-length bytes?
A. TRUE
B. FALSE
Answer: A) TRUE
Explanation:
Var binary - a variable-width string with a length of max-length bytes,
where the maximum number of bytes is declared as an optional
specifier to the type, and where the maximum number of bytes is
declared as an optional specifier to the type.
7. Is Python supports exception handling?
A. Yes
B. No
Page 4 of 13
iNeuron Intelligence Pvt Ltd
Answer: A) Yes
Explanation:
Unexpected events that can occur during a program's execution are
referred to as exceptions, and they can cause the program's normal
flow to be interrupted.
8. The % operator returns the ___.
A. Quotient
B. Divisor
C. Remainder
D. None of the mentioned above
Answer: C) Remainder
Explanation:
The % operator (it is an arithmetic operator) returns the amount that
was left over. This is useful for determining the number of times a
given number is multiplied by itself.
9. The [Link] ([i]) removes the item at the given position in the list?
A. True
B. False
Answer: A) True
Explanation:
Page 5 of 13
iNeuron Intelligence Pvt Ltd
The external is not a valid variable scope in PHP.
10. Python Dictionary is used to store the data in a ___ format.
A. Key value pair
B. Group value pair
C. Select value pair
D. None of the mentioned above
Answer: A) Key value pair
Explanation:
Python Dictionary is used to store the data in a key-value pair format,
which is similar to that of a database. The dictionary data type in
Python is capable of simulating the real-world data arrangement in
which a specific value exists for a specific key when the key is
specified.
11. The following is used to define a ___.
d={
<key>: <value>,
<key>: <value>,
Page 6 of 13
iNeuron Intelligence Pvt Ltd
<key>: <value>
Group
List
Dictionary
All of the mentioned above
Answer: C) Dictionary
12. Python Literals is used to define the data that is given in a
variable or constant?
A. True
B. False
Answer: A) True
Explanation:
It is possible to define literals in Python as data that is provided in a
variable or constant. Literal collections are supported in Python as
well as String and Numeric literals, Boolean and Boolean expressions,
Special literals, and Special expressions.
Page 7 of 13
iNeuron Intelligence Pvt Ltd
13. The if statement is the most fundamental decision-making
statement?
A. True
B. False
Answer: A) True
Explanation:
The if statement is the most fundamental decision-making
statement, and it determines whether or not the code should be
executed based on whether or not the condition is met. If the
condition in the if statement is met, a code body is executed, and the
code body is not otherwise executed.
14. Amongst which of the following if syntax is true?
if condition:
#Will executes this block if the condition is true
if condition
#Will executes this block if the condition is true
if(condition)
Page 8 of 13
iNeuron Intelligence Pvt Ltd
#Will executes this block if the condition is true
None of the mentioned above
Answer: A)
if condition:
#Will executes this block if the condition is true
15. Amongst which of the following is / are the conditional
statement in Python code?
A. if a<=100:
B. if (a >= 10)
C. if (a => 200)
D. None of the mentioned above
Answer: A) if a<=100:
Explanation:
The if statement in Python is used to make decisions in various
situations. It contains a body of code that is only executed when the
condition specified in the if statement is true; if the condition is not
met, the optional else statement is executed, which contains code
that is executed when the else condition is met.
Page 9 of 13
iNeuron Intelligence Pvt Ltd
16. Amongst which of the following is / are the conditional
statement in Python code?
A. if a<=100:
B. if (a >= 10)
C. if (a => 200)
D. None of the mentioned above
Answer: A) if a<=100:
Explanation:
The if statement in Python is used to make decisions in various
situations. It contains a body of code that is only executed when the
condition specified in the if statement is true; if the condition is not
met, the optional else statement is executed, which contains code
that is executed when the else condition is met.
17. Which of the following is false regarding conditional statement in
Python?
A. If-elif is the shortcut for the if-else chain
B. We use the dictionary to replace the Switch case statement
C. We cannot use python classes to implement the switch case
statement
D. None of the mentioned above
Answer: C) We cannot use python classes to implement the switch
case statement
Explanation:
Page 10 of 13
iNeuron Intelligence Pvt Ltd
It is possible to shorten the if-else chain by using the if-elif construct.
Use the if-elif statement and include an else statement at the end,
which will be executed if none of the if-elif statements in the
previous section are true.
18. In a Python program, Nested if Statements denotes?
A. if statement inside another if statement
B. if statement outside the another if statement
C. Both A and B
D. None of the mentioned above
Answer: A) if statement inside another if statement
Explanation:
Nesting an if statement within another if statement is referred to as
nesting in the programming community. It is not always necessary to
use a simple if statement; instead, you can combine the concepts of
if, if-else, and even if-elif-else statements to create a more complex
structure.
19. What will be the output of the following Python code?
a=7
if a>4: print("Greater")
Greater
Page 11 of 13
iNeuron Intelligence Pvt Ltd
None of the mentioned above
Answer: A) Greater
20. What will be the output of the following Python code?
X,y = 12,14
if(x +y==26):
print("true")
else:
print("false")
a) true
b) false
Answer: A) true
Page 12 of 13
iNeuron Intelligence Pvt Ltd
Explanation:
In this code the value of x = 12 and y = 14, when we add x and y the
value will be 26 so x + y= =26. Hence, the given condition will be true.
Page 13 of 13
iNeuron Intelligence Pvt Ltd
1. What will be the output of the following Python code?
x=13
if x>12 or x<15 and x==16:
print("Given condition matched")
else:
print("Given condition did not match")
Given condition matched
Given condition did not match
Both A and B
None of the mentioned above
Answer: A) Given condition matched
Explanation:
In this code the value of x = 13, and the condition 13>12 or 13<15 is
true but 13==16 becomes falls. So, the if part will not execute and
program control will switch to the else part of the program and
output will be "Given condition did not match".
Page 2 of 17
iNeuron Intelligence Pvt Ltd
2. Consider the following code segment and identify what will be the
output of given Python code?
a = int(input("Enter an integer: "))
b = int(input("Enter an integer: "))
if a <= 0:
b = b +1
else:
a=a+1
if inputted number is a negative integer then b = b +1
if inputted number is a positive integer then a = a +1
Both A and B
None of the mentioned above
Answer: C) Both A and B
Explanation:
Page 3 of 17
iNeuron Intelligence Pvt Ltd
In above code, if inputted number is a negative integer, then b = b +1
and if inputted number is a positive integer, then a = a +1. Hence, the
output will be depending on inputted number.
3. The writelines() method is used to write multiple strings to a file?
A. True
B. False
Answer: A) True
Explanation:
In order to write multiple strings to a file, the writelines() method is
used. The writelines() method requires an iterable object, such as a
list, tuple, or other collection of strings, to be passed to it.
4. A text file contains only textual information consisting of ___.
A. Alphabets
B. Numbers
C. Special symbols
D. All of the mentioned above
Answer: D) All of the mentioned above
Explanation:
Unlike other types of files, text files contain only textual information,
which can be represented by alphabets, numbers, and other special
symbols. These types of files are saved with extensions such
Page 4 of 17
iNeuron Intelligence Pvt Ltd
[Link],.py,.c,.csv,.html, and so on. Each byte in a text file corresponds
to one character in the text.
5. Amongst which of the following is / are the method used to
unpickling data from a binary file?
A. load()
B. set() method
C. dump() method
D. None of the mentioned above
Answer: B) set() method
Explanation:
The load() method is used to unpickle data from a binary file that has
been compressed. The binary read (rb) mode is used to load the file
that is to be loaded. If we want to use the load() method, we can
write Store object = load(file object) in our program. The pickled
Python object is loaded from a file with a file handle named file
object and stored in a new file handle named store object. The
pickled Python object is loaded from a file with a file handle named
file object and stored in a new file handle named store object.
6. Amongst which of the following is / are the method of convert
Python objects for writing data in a binary file?
A. set() method
B. dump() method
C. load() method
D. None of the mentioned above
Page 5 of 17
iNeuron Intelligence Pvt Ltd
Answer: B) dump() method
Explanation:
The dump() method is used to convert Python objects into binary
data that can be written to a binary file. The file into which the data
is to be written must be opened in binary write mode before the data
can be written.
7. The readline() is used to read the data line by line from the text
file.
A. True
B. False
Answer: A) True
Explanation:
It is necessary to use readline() in order to read the data from a text
file line by line. The lines are displayed by employing the print()
command. When the readline() function reaches the end of the file,
it will return an empty string.
Discuss this Question
8. The module Pickle is used to ___.
A. Serializing Python object structure
B. De-serializing Python object structure
C. Both A and B
Page 6 of 17
iNeuron Intelligence Pvt Ltd
D. None of the mentioned above
Answer: C) Both A and B
Explanation:
Pickle is a Python module that allows you to save any object
structure along with its associated data. Pickle is a Python module
that can be used to serialize and de-serialize any type of Python
object structure. Serialization is the process of converting data or an
object stored in memory to a stream of bytes known as byte streams,
which is a type of data stream.
Page 7 of 17
iNeuron Intelligence Pvt Ltd
9. Write a python program to print even length words in a string.
Ans-
Page 8 of 17
iNeuron Intelligence Pvt Ltd
10. Write a Python program to declare, assign and print the string.
Ans-
Page 9 of 17
iNeuron Intelligence Pvt Ltd
11. An ___ statement has less number of conditional checks
than two successive ifs.
A. if else if
B. if elif
C. if-else
D. None of the mentioned above
Answer: C) if-else
Explanation:
A single if-else statement requires fewer conditional checks
than two consecutives if statements. If the condition is true, the
if-else statement is used to execute both the true and false
parts of the condition in question. The condition is met, and
therefore the if block code is executed, and if the condition is
not met, the otherwise block code is executed.
12. In Python, the break and continue statements, together
are called ___ statement.
A. Jump
B. goto
C. compound
D. None of the mentioned above
Answer: B) goto
Page 10 of 17
iNeuron Intelligence Pvt Ltd
Explanation:
With the go to statement in Python, we are basically telling the
interpreter to skip over the current line of code and directly
execute another one instead of the current line of code. You
must place a check mark next to the line of code that you want
the interpreter to execute at this time in the section labelled
"target."
Page 11 of 17
iNeuron Intelligence Pvt Ltd
13. What will be the output of the following Python code?
num = 10
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
Positive number
Negative number
Real number
None of the mentioned above
Answer: A) Positive number
14. The elif statement allows us to check multiple expressions.
A. True
B. False
Answer: A) True
Explanation:
Page 12 of 17
iNeuron Intelligence Pvt Ltd
It is possible to check multiple expressions for TRUE and to execute a
block of code as soon as one of the conditions evaluates to TRUE
using the elif statement. The elif statement is optional in the same
way that the else statement is.
15. What will be the output of the following Python code?
i=5
if i>11 : print ("i is greater than 11")
No output
Abnormal termination of program
Both A and B
None of the mentioned above
Answer: C) Both A and B
Explanation:
In the above code, the assign value of i = 5 and as mentioned in the
condition if 5 > 11: print ("i is greater than 11"), here 5 is not greater
than 11 so condition becomes false and there will not be any output
and program will be abnormally terminated.
Page 13 of 17
iNeuron Intelligence Pvt Ltd
16. What will be the output of the following Python code?
a = 13
b = 15
print("A is greater") if a > b else print("=") if a == b else print("B is
greater")
A is greater
B is greater
Both A and B
None of the mentioned above
Answer: B) B is greater
17. If a condition is true the not operator is used to reverse the
logical state?
A. True
B. False
Answer: A) True
Explanation:
Page 14 of 17
iNeuron Intelligence Pvt Ltd
In order to make an if statement test whether or not something
occurred, we must place the word not in front of our condition.
When the not operator is used before something that is false, it
returns true as a result. And when something that is true comes
before something that is false, we get False. That is how we
determine whether or not something did not occur as claimed. In
other words, the truth value of not is the inverse of the truth value of
yes. So, while it may not appear to be abstract, this operator simply
returns the inverse of the Boolean value.
18. Loops are known as ___ in programming.
A. Control flow statements
B. Conditional statements
C. Data structure statements
D. None of the mentioned above
Answer: A) Control flow statements
Explanation:
The control flow of a program refers to the sequence in which the
program's code is executed. Conditional statements, loops,
and function calls all play a role in controlling the flow of a Python
program's execution.
Page 15 of 17
iNeuron Intelligence Pvt Ltd
19. The for loop in Python is used to ___ over a sequence or other
iterable objects.
Jump
Iterate
Switch
All of the mentioned above
Answer: B) Iterate
Explanation:
It is possible to iterate over a sequence or other iterable objects
using the for loop in Python. The process of iterating over a sequence
is referred to as traversal. Following syntax can be follow to use for
loop in Python Program –
for val in sequence:
...
loop body
...
For loop does not require an indexing variable to set beforehand.
Discuss this Question
Page 16 of 17
iNeuron Intelligence Pvt Ltd
20. With the break statement we can stop the loop before it has
looped through all the items?
True
False
Answer: A) True
Explanation:
In Python, the word break refers to a loop control statement. It
serves to control the sequence of events within the loop. If you want
to end a loop and move on to the next code after the loop; the break
command can be used to do so. When an external condition causes
the loop to terminate, it represents the common scenario in which
the break function is used in Python.
Page 17 of 17