You are on page 1of 279

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}

set1.add (4)

set1.add (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}

Q12.What will the below Python code do?


set1={"a",3,"b",3}
set1.remove(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]
list1.pop (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"]
list1.insert(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

1.integer
2.long
3.float
4.complex
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)
x.real
Output
7.0
x.imag
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) sys.version(0)
c) sys.version()
d) sys.version
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 (string1.join(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

5.How 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”
string1.replace(‘u’,’y’)
happy

Q11.Which 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

Q12.Explain 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 shell.id
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.

16.The 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 shell.id
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.

2.If 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) d.delete(“john”:40)
b) d.delete(“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 a.pop


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,

4.Usage 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 = array.array('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?

20.what 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]
list1.remove(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. math.factorial(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)

tuple1.pop(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):
var1.pop(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.

19.How 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
opera.ons will execute in a specific order. In Python the opera.on precedence
follows as per the acronym PEMDAS.
Parenthesis
Exponent
Mul.plica.on
Addi.on
Division
Subtrac.on
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 rela.onal operators?


Ans- Rela.onal operators are known as condi.onal 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 func.on 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 conver.ng 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. Func.onal 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, suppor.ng object-


oriented, structured, and func.onal programming.

12. When Python is dealing with iden.fiers, is it case sensi.ve?


1. Yes
2. No
3. Machine dependent
4. Can’t say
Answer. a. It is case sensi.ve.

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 func.on in Python is:


1. Print ()
2. Seed ()
3. Sqrt ()
4. Factorial ()

Answer. a. 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. The
print func.on is a built-in func.on which prints a value directly to the system
output.

17. Which of the following defini.ons 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 defini.ons 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 list.pop ([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

as.txt,.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
iNeuron Intelligence Pvt Ltd

1. The continue keyword is used to ___ the current iteration in a


loop.

A. Initiate
B. Start
C. End
D. None of the mentioned above

Answer: C) End

Explanation:

The continue keyword is used to terminate the current iteration of a


for loop (or a while loop) and proceed to the next iteration of the for
loop (or while loop). With the continue statement, you have the
option of skipping over the portion of a loop where an external
condition is triggered, but continuing on to complete the remainder
of the loop.

2. Amongst which of the following is / are true about the while loop?

A. It continually executes the statements as long as the given


condition is true
B. It first checks the condition and then jumps into the instructions
C. The loop stops running when the condition becomes fail, and
control will move to the next line of code.
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

While loops are used to execute statements repeatedly as long as the


condition is met, they are also used to execute statements once. It
Page 2 of 14
iNeuron Intelligence Pvt Ltd

begins by determining the condition and then proceeds to execute


the instructions.

3. The ___ is a built-in function that returns a range object that


consists series of integer numbers, which we can iterate using a for
loop.

A. range()
B. set()
C. dictionary{}
D. None of the mentioned above

Answer: A) range()

Explanation:

This type represents an immutable sequence of numbers and is


commonly used in for loops to repeat a specific number of times a
given sequence of numbers.

4. What will be the output of the following Python code?

for i in range(6):

print(i)

1
Page 3 of 14
iNeuron Intelligence Pvt Ltd

None of the mentioned above

Answer: A)

Page 4 of 14
iNeuron Intelligence Pvt Ltd

5. The looping reduces the complexity of the problems to the ease of


the problems?

A. True
B. False

Answer: A) True

Explanation:

The looping simplifies the complex problems into the easy ones. It
enables us to alter the flow of the program so that instead of writing
the same code again and again, we can repeat the same code for a
finite number of times.

6. The while loop is intended to be used in situations where we do


not know how many iterations will be required in advance?

A. True
B. False

Answer: A) True

Explanation:

Page 5 of 14
iNeuron Intelligence Pvt Ltd

The while loop is intended to be used in situations where we do not


know how many iterations will be required in advance.

7. Amongst which of the following is / are true with reference to


loops in Python?

A. It allows for code reusability to be achieved.


B. By utilizing loops, we avoid having to write the same code over
and over again.
C. We can traverse through the elements of data structures by
utilizing looping.
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

Following point's shows the importance of loops in Python.

• It allows for code reusability to be achieved.


• By utilizing loops, we avoid having to write the same code over
and over again.
• We can traverse through the elements of data structures by
utilizing looping.

8. A function is a group of related statements which designed


specifically to perform a ___.

A. Write code
B. Specific task

Page 6 of 14
iNeuron Intelligence Pvt Ltd

C. Create executable file


D. None of the mentioned above

Answer: B) Specific task

Explanation:

A function is a group of related statements designed specifically to


perform a specific task. Functions make programming easier to
decompose a large problem into smaller parts. The function allows
programmers to develop an application in a modular way. As our
program grows larger and larger, functions make it more organized
and manageable.

9. Amongst which of the following is a proper syntax to create a


function in Python?

def function_name(parameters):

...

Statements

...

def function function_name:

...

Statements

Page 7 of 14
iNeuron Intelligence Pvt Ltd

...

def function function_name(parameters):

...

Statements

...

None of the mentioned above

Answer: A)

def function_name(parameters):

...

Statements

...

Explanation:

The range(6) is define as function. Loop will print the number from 0.

10. Once we have defined a function, we can call it?

Page 8 of 14
iNeuron Intelligence Pvt Ltd

A. True
B. False

Answer: A) True

Explanation:

Once a function has been defined, it can be called from another


function, a program, or even from the Python prompt itself.

11. Amongst which of the following shows the types of function calls
in Python?

A. Call by value
B. Call by reference
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:

Call by value and Call by reference are the types of function calls in
Python.

12. What will be the output of the following Python code?

def show(id,name):

print("Your id is :",id,"and your name is :",name)

Page 9 of 14
iNeuron Intelligence Pvt Ltd

show(12,"deepak")

Your id is: 12 and your name is: deepak

Your id is: 11 and your name is: Deepak

Your id is: 13 and your name is: Deepak

None of the mentioned above

Answer: A) Your id is: 12 and your name is: Deepak

13. Amongst which of the following is a function which does not have
any name?

Del function

Show function

Lambda function

None of the mentioned above

Answer: C) Lambda function

14. Can we pass List as an argument in Python function?

A. Yes

Page 10 of 14
iNeuron Intelligence Pvt Ltd

B. No

Answer: A) Yes

Explanation:

In a function, we can pass any data type as an argument, such as a


string or a number or a list or a dictionary, and it will be treated as if
it were of that data type inside the function.

15. A method refers to a function which is part of a class?

A. True
B. False

Answer: A) True

Explanation:

A method is a function that is a part of a class that has been defined.


It is accessed through the use of an instance or object of the class. A
function, on the other hand, is not restricted in this way: it simply
refers to a standalone function.

16. The return statement is used to exit a function?

A. True
B. False

Answer: A) True

Page 11 of 14
iNeuron Intelligence Pvt Ltd

17. Scope and lifetime of a variable declared in a function exist till the
function exists?

A. True
B. False

Answer: A) True

Explanation:

It is the portion of a program where a variable is recognized that is


referred to as its scope. It is not possible to see the parameters and
variables defined within a function from outside of the function. As a
result, they are limited in their application.

18. File handling in Python refers the feature for reading data from
the file and writing data into a file?

A. True
B. False

Answer: A) True

Explanation:

File handling is the capability of reading data from and writing it into
a file in Python. Python includes functions for creating and
manipulating files, whether they are flat files or text documents.

Page 12 of 14
iNeuron Intelligence Pvt Ltd

19. Amongst which of the following is / are the key functions used for
file handling in Python?

A. open() and close()


B. read() and write()
C. append()
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

The key functions used for file handling in Python


are: open(), close(), read(), write(), and append(). the open() function
is used to open an existing file, close() function is used to close a file
which opened, read() function is used when we want to read the
contents from an existing file, write() function is used to write the
contents in a file and append() function is used when we want to
append the text or contents to a specific position in an existing file.

Page 13 of 14
iNeuron Intelligence Pvt Ltd

20. Write a Python program to count vowels in a string.


Ans-

Page 14 of 14
iNeuron Intelligence Pvt Ltd

1. How to Implement the program by creating functions to check


vowel and to count vowels.

Ans-

2. Amongst which of the following function is / are used to create a


file and writing data?

A. append()
B. open()
C. close()
D. None of the mentioned above

Answer: B) open()

Explanation:

Page 2 of 11
iNeuron Intelligence Pvt Ltd

To create a text file, we call the open() method and pass it the
filename and the mode parameters to the function.

3. How to Create multiple copies of a string by using multiplication


operator.

Ans-

4. How to Append text at the end of the string using += Operator?

Page 3 of 11
iNeuron Intelligence Pvt Ltd

Ans-

5. How to Check if a substring presents in a string using 'in' operator?

Ans-

Page 4 of 11
iNeuron Intelligence Pvt Ltd

6. How to assign Hexadecimal values in the string and print it in the


string format?

Ans-

7. How to print double quotes with the string variable?

Page 5 of 11
iNeuron Intelligence Pvt Ltd

8. How to Ignore escape sequences in the string?

Ans-

9.Write a python program to check whether a string contains a


number or not.

Ans- Input:
str1 = "8789"
str2 = "Hello123"
str3 = "123Hello"
str4 = "123 456" #contains space

# function call
str1.isdigit()
str2.isdigit()
str3.isdigit()
str4.isdigit()

Page 6 of 11
iNeuron Intelligence Pvt Ltd

Output:
True
False
False
False

10. What is Factorial of a Number?


Factorial of a number is the product of all positive integers from 1 to
that number. It is denoted by the symbol “!”. For example, factorial of
5 is 5! = 5*4*3*2*1 = 120 and factorial of 8 is 8! = 8 * 7 * 6 * 5 * 4 * 3
* 2 * 1 which equals to 40320.
By default, the factorial of 0 is 1, and the Factorial of a negative
number is not defined.

In mathematics, a factorial is denoted by “!“. Therefore, the factorial


of n is given by the formula
n! = n x (n-1) x (n-2) x (n-3) … x1.

11. How to Search and Sort in Python?

Ans- Searching algorithms are used to locate an element or retrieve it


from a data structure. These algorithms are divided into two
categories based on the type of search operation, namely sequential
search (Linear Search) and interval search (Binary Search). Sorting is
the process of arranging data in a specific format. Sorting algorithms
specify how to sort data in a specific order such as numerical order
(ascending or descending order) or lexical order.

Page 7 of 11
iNeuron Intelligence Pvt Ltd

12. How to Determine if a Number is Prime or Not?


Ans- To check if a number is prime, follow these steps:

1. Begin by taking a number as input from the user.


2. Then, start counting through natural numbers, beginning
at 2.
3. Check whether the input number can be divided evenly by
any of these natural numbers.
4. If the input number is divisible by any of these numbers, it
is not a prime number; otherwise, it is a prime number.
5. Finally, exit the program.

13. How to Sort a list?

Create a function in Python that accepts two parameters. The first


will be a list of numbers. The second parameter will be a string that
can be one of the following values: asc, desc, and none.

If the second parameter is “asc,” then the function should return a


list with the numbers in ascending order. If it’s “desc,” then the list
should be in descending order, and if it’s “none,” it should return the
original list unaltered.

Page 8 of 11
iNeuron Intelligence Pvt Ltd

14. How to Convert a decimal number into binary

Write a function in Python that accepts a decimal number and


returns the equivalent binary number. To make this simple, the
decimal number will always be less than 1,024, so the binary number
returned will always be less than ten digits long.

15. Create a calculator function.

Write a Python function that accepts three parameters. The first


parameter is an integer. The second is one of the following
mathematical operators: +, -, /, or . The third parameter will also be
an integer.

The function should perform a calculation and return the results. For
example, if the function is passed 6 and 4, it should return 24.

Page 9 of 11
iNeuron Intelligence Pvt Ltd

20. How to Extract the mobile number from the given string in
Python?

Ans-

21.How to replace a special string from a given paragraph with


another string in Python?

Ans-

Page 10 of 11
iNeuron Intelligence Pvt Ltd

22. How to find the ASCII value of each character of the string in
Python?

Ans-

Page 11 of 11
iNeuron Intelligence Pvt Ltd

Q1. What are iden.ty operators?


Ans- this is used to verify whether two values are on the same part of
the memory or not. There are two types of iden.ty operators:

a) Is: return true if two operands are iden.cal


b) is not: returns true if two operands are not iden.cal

Q2. What is the difference between a=10 and a==10?

Ans- The expression a=10 assigns the value 10 to variable a, whereas


a==10 checks if the value of is equal to 10 or not. If yes then it
returns ‘True’ else it will return ‘False’.

Q3. What is an expression?


Ans- Logical line of code that we write while programming, are called
expressions. An expression can be broken into operators and
operands . It is therefore said that an expression is a combina.on of
one or more operands and zero or more operators that are together
used to compute a value.

Q4. What are the basic rules of operator precedence in python?

Ans- The basic rule of operator precedence in python is as follows:

1. Expressions must be evaluated from leS to right


2. Expressions of parenthesis are performed first.
3. In python the opera.on procedure follows as per the acronym
PEMDAS:
a) Parenthesis

Page 2 of 9
iNeuron Intelligence Pvt Ltd

b) Exponent
c) Mul.plica.on
d) Division
e) Addi.on
f) Subtrac.on

4. Mathema.cal operators are of higher precedence and the


Boolean operators are of lower precedence. Hence,
mathema.cal opera.ons are performed before Boolean
opera.ons.

Q5. Arrange the following operators from high to low precedence.


a) Assignment
b) Exponent
c) Addi.on and Subtrac.on
d) Rela.onal Operators
e) Equality operators
f) Logical operators
g) Mul.plica.on, division, floor division and modulus

Ans- 1. Exponent
2. Mul.plica.on, division, floor division and modulus
3. Addi.on and Subtrac.on
4. Rela.onal Operators
5. Equality operators
6. Assignment
7. Logical operators

Q6. Is it possible to change the order of evalua.on in an expression.

Page 3 of 9
iNeuron Intelligence Pvt Ltd

Ans- Yes, it is possible to change order of evalua.on of an expression.


Suppose you want to perform addi.on before mul.plica.on in an
expression, then you can simply put the addi.on expression in
parenthesis.

Q7. What is the difference between implicit and explicit expression?


Ans- Conversion is the process of conver.ng one data type into
another. Two types of conversion in Python as follows:

1. Implicit type conversion


2. Explicit type conversion

Q8. What is a statement?


Ans- A complete unit of code that Python interpreter can execute is
called statement.

Q9. What is input statement?


Ans- The input statement is used to get user input from the
keyboard. The syntax for input () func.on is as follows:

Q10. Look at the following code and find the solu.on.

Page 4 of 9
iNeuron Intelligence Pvt Ltd

Ans-

Q11. What is Associa.vity of Python operators? What are non-


associa.ve operators?
Ans- Associa.vity defines the order in which an expression will be
evaluated if it has more than one operator having same precedence.
In such a case generally leS to right associa.vity is followed.

Operators like assignment or comparison operators have no


associa.vity and known as Non associa.ve operators.

Q12. What are control statements?


Ans- They are used to control the follow of program execu.on. They
help in deciding the next steps under specific condi.ons also allow
repe..ons of program for certain number of .mes.

Two types of control statements are as follows:


1. Condi.onal branching
• If

Page 5 of 9
iNeuron Intelligence Pvt Ltd

• If…. else

• Nested if statements

2.Loops
While: repeat a block of statements as long as a given condi.on is
true

For: repeat a block of statements for certain number of .mes.

Q13. Write a code to print the star pahern.

Page 6 of 9
iNeuron Intelligence Pvt Ltd

Ans-

Q14. Write code to produce the following pahern:


1
22
333
4444
Ans-

Q15. Write a code to generate the following pahern.


1

Page 7 of 9
iNeuron Intelligence Pvt Ltd

12
123
1234
Ans-

Q16. Write code to spell a word entered by the user.


Ans-

Q17. What are the statements to control a loop?


Ans – The following three statements can be used to control as loop:
a) break: breaks the execu.on of the loop and jumps to next
statement aSer the loop.

Page 8 of 9
iNeuron Intelligence Pvt Ltd

b) Con.nue: takes the control back to the top of the loop without
execu.ng the remaining statements.

c) pass: does nothing

Q18. What is the meaning of condi.onal branching?


Ans- Deciding whether certain sets of instruc.ons must be executed
or not based on the value of an expression is called condi.onal
branching.

Q19. What is the difference between the con.nue and pass


statement?
Ans- Pass does nothing whereas con.nue starts the next itera.ons of
the loop.

Q20. What is Self-used for in Python?

Ans- It is used to represent the instance of the class. This is because


in Python, the ‘@’ syntax is not used to refer to the instance
ahributes.

Page 9 of 9
iNeuron Intelligence Pvt Ltd

Q1. What are Decorators in Python?

Ans- Decorator is a very useful tool in Python that is used by


programmers to alter the changes in the behaviour of classes and
func?ons.

Q2. What is a Python PATH?

Ans- This is an environment variable used to import a variable and


check for the presence of variables present in different directories.

Q3. Create a module in Python.

Ans- Crea?ng a module in Python is fairly simple. First, open a text


editor and create a new file. Add the code you want to include in the
module. You can include various func?ons and classes, as well as
global variables.
Save the file with a .py extension (e.g. myModule.py).
Import the module using the import statement.
Use the module's func?ons and classes in your program.
Q4. How memory can be managed in Python?

Ans- In Python, the memory is managed using the Python Memory


Manager. The manager allocates memory in the form of a private
heap space dedicated to Python. All objects are now stored in this
Hype and due to its private feature, it is restricted from the
programmer.

Page 2 of 9
iNeuron Intelligence Pvt Ltd

Q5. What do you mean by Python literals?

A literal is a simple and direct form of expressing a value. Literals


reflect the primi?ve type op?ons available in that language. Integers,
floa?ng-point numbers, Booleans, and character strings are some of
the most common forms of literal. Python supports the following
literals:

Literals in Python relate to the data that is kept in a variable or


constant. There are several types of literals present in Python

String Literals: It’s a sequence of characters wrapped in a set of


codes. Depending on the number of quota?ons used, there can be
single, double, or triple strings. Single characters enclosed by single
or double quota?ons are known as character literals.

Numeric Literals: These are unchangeable numbers that may be


divided into three types: integer, float, and complex.

Boolean Literals: True or False, which signify ‘1’ and ‘0,’ respec?vely,
can be assigned to them.

Special Literals: It’s used to categorize fields that have not been
generated. ‘None’ is the value that is used to represent it.

• String literals: “halo” , ‘12345’


• Int literals: 0,1,2,-1,-2
• Long literals: 89675L
• Float literals: 3.14
• Complex literals: 12j
• Boolean literals: True or False
• Special literals: None
Page 3 of 9
iNeuron Intelligence Pvt Ltd

• Unicode literals: u”hello”


• List literals: [], [5, 6, 7]
• Tuple literals: (), (9,), (8, 9, 0)
• Dict literals: {}, {‘x’:1}
• Set literals: {8, 9, 10}

Q6. What is pep 8?


PEP 8, olen known as PEP8 or PEP-8, is a document that outlines
best prac?ces and recommenda?ons for wri?ng Python code. It was
wrimen in 2001 by Guido van Rossum, Barry Warsaw, and Nick
Coghlan. The main goal of PEP 8 is to make Python code more
readable and consistent.

Python Enhancement Proposal (PEP) is an acronym for Python


Enhancement Proposal, and there are numerous of them. A Python
Enhancement Proposal (PEP) is a document that explains new
features suggested for Python and details elements of Python for the
community, such as design and style.

Q7. What are global, protected, and private amributes in Python?

The amributes of a class are also called variables. There are three
access modifiers in Python for variables, namely

a. public – The variables declared as public are accessible


everywhere, inside or outside the class.

b. private – The variables declared as private are accessible only


within the current class.

c. protected – The variables declared as protected are accessible only


within the current package.
Page 4 of 9
iNeuron Intelligence Pvt Ltd

Amributes are also classified as:

– Local a2ributes are defined within a code-block/method and can


be accessed only within that code-block/method.

– Global a2ributes are defined outside the code-block/method and


can be accessible everywhere.

Q8. What are Keywords in Python?

Keywords in Python are reserved words that are used as iden?fiers,


func?on names, or variable names. They help define the structure
and syntax of the language.

Q9. How can you concatenate two tuples?

Let’s say we have two tuples like this ->

tup1 = (1, ”a”, True)

tup2 = (4,5,6)

Concatena?on of tuples means that we are adding the elements of


one tuple at the end of another tuple.

Q10. What are func?ons in Python?

Page 5 of 9
iNeuron Intelligence Pvt Ltd

Ans: Func?ons in Python refer to blocks that have organized, and


reusable codes to perform single, and related events. Func?ons are
important to create bemer modularity for applica?ons that reuse a
high degree of coding. Python has a number of built-in func?ons like
print(). However, it also allows you to create user-defined func?ons.

Q11. What are Pandas?

Pandas is an open-source python library that has a very rich set of


data structures for data-based opera?ons. Pandas with their cool
features fit in every role of data opera?on, whether it be academics
or solving complex business problems. Pandas can deal with a large
variety of files and are one of the most important tools to have a grip
on.

Q12. How can you randomize the items of a list in place in Python?

Ans-

Q13. How can you generate random numbers in Python?

Page 6 of 9
iNeuron Intelligence Pvt Ltd

Ans: Random module is the standard module that is used to generate


a random number. The method is defined as:

The statement random.random() method return the floa?ng-point


number that is in the range of [0, 1). The func?on generates random
float numbers. The methods that are used with the random class are
the bound methods of the hidden instances. The instances of the
Random can be done to show the mul?-threading programs that
creates a different instance of individual threads. The other random
generators that are used in this are:

1. randrange (a, b): it chooses an integer and define the range in-
between [a, b). It returns the elements by selec?ng it randomly
from the range that is specified. It doesn’t build a range object.
2. Uniform (a, b): it chooses a floa?ng point number that is defined
in the range of [a,b). Iyt returns the floa?ng point number
3. Normalvariate (mean, sdev): it is used for the normal distribu?on
where the mu is a mean and the sdev is a sigma that is used for
standard devia?on.
4. The Random class that is used and instan?ated creates
independent mul?ple random number generators.

Q14. What is the difference between range & xrange?

Ans: For the most part, xrange and range are the exact same in terms
of func?onality. They both provide a way to generate a list of integers
for you to use, however you please. The only difference is that range
returns a Python list object and x range returns an xrange object.

This means that xrange doesn’t actually generate a sta?c list at run-
?me like range does. It creates the values as you need them with a
Page 7 of 9
iNeuron Intelligence Pvt Ltd

special technique called yielding. This technique is used with a type of


object known as generators. That means that if you have a really
gigan?c range, you’d like to generate a list for, say one billion, xrange
is the func?on to use.

Q15. What is pickling and unpickling?

Ans: Pickle module accepts any Python object and converts it into a
string representa?on and dumps it into a file by using dump func?on,
this process is called pickling. While the process of retrieving original
Python objects from the stored string representa?on is called
unpickling.

Q16. What are the generators in python?

Ans: Func?ons that return an iterable set of items are called


generators.

Q17. How will you capitalize the first lemer of string?

Ans: In Python, the capitalize () method capitalizes the first lemer of a


string. If the string already consists of a capital lemer at the beginning,
then, it returns the original string.

Q18. How will you convert a string to all lowercase?

Ans: To convert a string to lowercase, lower () func?on can be used.

Q19. How to comment mul?ple lines in python?

Ans: Mul?-line comments appear in more than one line. All the lines
to be commented are to be prefixed by a #. You can also a very

Page 8 of 9
iNeuron Intelligence Pvt Ltd

good shortcut method to comment mul?ple lines. All you need to do


is hold the ctrl key and lel click in every place wherever you want to
include a # character and type a # just once. This will comment all the
lines where you introduced your cursor.

Q20. What is the purpose of ‘is’, ‘not’ and ‘in’ operators?

Ans: Operators are special func?ons. They take one or more values
and produce a corresponding result.

is: returns true when 2 operands are true (Example: “a” is ‘a’)

not: returns the inverse of the Boolean value

in: checks if some element is present in some sequence

Page 9 of 9
iNeuron Intelligence Pvt Ltd

Q1. What is the usage of help () and dir () func8on in Python?

Ans: Help() and dir() both func8ons are accessible from the Python
interpreter and used for viewing a consolidated dump of built-in
func8ons.

Q2. Whenever Python exits, why isn’t all the memory de-allocated?

Ans:

1. Whenever Python exits, especially those Python modules which


are having circular references to other objects or the objects that
are referenced from the global namespaces are not always de-
allocated or freed.
2. It is impossible to de-allocate those por8ons of memory that are
reserved by the C library.
3. On exit, because of having its own efficient clean up mechanism,
Python would try to de-allocate/destroy every other object.

Q3. What does this mean: *args, **kwargs? And why would we use it?

Ans: We use *args when we aren’t sure how many arguments are
going to be passed to a func8on, or if we want to pass a stored list or
tuple of arguments to a func8on. **kwargs is used when we don’t
know how many keyword arguments will be passed to a func8on, or it
can be used to pass the values of a dic8onary as keyword arguments.
The iden8fiers args and kwargs are a conven8on, you could also use
*bob and **billy but that would not be wise.

Page 2 of 9
iNeuron Intelligence Pvt Ltd

Q4. Explain split(), sub(), subn() methods of “re” module in Python.

Ans: To modify the strings, Python’s “re” module is providing 3


methods. They are:

• split() – uses a regex paXern to “split” a given string into a list.


• sub() – finds all substrings where the regex paXern matches and
then replace them with a different string
• subn() – it is similar to sub() and also returns the new string along
with the no. of replacements.

Q5. What are nega8ve indexes and why are they used?

Ans: The sequences in Python are indexed and it consists of the


posi8ve as well as nega8ve numbers. The numbers that are posi8ve
uses ‘0’ that is uses as first index and ‘1’ as the second index and the
process goes on like that.

The index for the nega8ve number starts from ‘-1’ that represents the
last index in the sequence and ‘-2’ as the penul8mate index and the
sequence carries forward like the posi8ve number.

The nega8ve index is used to remove any new-line spaces from the
string and allow the string to except the last character that is given as
S[:-1]. The nega8ve index is also used to show the index to represent
the string in correct order.

Q6. What are Python packages?

Ans: Python packages are namespaces containing mul8ple modules.

Page 3 of 9
iNeuron Intelligence Pvt Ltd

Q7.How can files be deleted in Python?

Ans: To delete a file in Python, you need to import the OS Module.


Ader that, you need to use the os. remove() func8on.

Q8. What advantages do NumPy arrays offer over (nested) Python


lists?

Ans:

1. Python’s lists are efficient general-purpose containers. They


support (fairly) efficient inser8on, dele8on, appending, and
concatena8on, and Python’s list comprehensions make them
easy to construct and manipulate.
2. They have certain limita8ons: they don’t support “vectorized”
opera8ons like elementwise addi8on and mul8plica8on, and the
fact that they can contain objects of differing types mean that
Python must store type informa8on for every element, and must
execute type dispatching code when opera8ng on each element.
3. NumPy is not just more efficient; it is also more convenient. You
get a lot of vector and matrix opera8ons for free, which
some8mes allow one to avoid unnecessary work. And they are
also efficiently implemented.
4. NumPy array is faster and You get a lot built in with NumPy, FFTs,
convolu8ons, fast searching, basic sta8s8cs, linear
algebra, histograms, etc.

Page 4 of 9
iNeuron Intelligence Pvt Ltd

Q9. How to remove values to a python array?

Ans: Array elements can be removed


using pop() or remove() method. The difference between these
two func8ons is that the former returns the deleted value
whereas the laXer does not.

Q10. Does Python have OOps concepts?

Ans: Python is an object-oriented programming language. This means


that any program can be solved in python by crea8ng an object
model. However, Python can be treated as a procedural as well as
structural language.

Q11. What is the difference between deep and shallow copy?

Ans: Shallow copy is used when a new instance type gets created and
it keeps the values that are copied in the new instance. Shallow copy
is used to copy the reference pointers just like it copies the values.
These references point to the original objects and the changes made
in any member of the class will also affect the original copy of
it. Shallow copy allows faster execu8on of the program and it depends
on the size of the data that is used.

Deep copy is used to store the values that are already copied. Deep
copy doesn’t copy the reference pointers to the objects. It makes the
reference to an object and the new object that is pointed by some
other object gets stored. The changes made in the original copy won’t
Page 5 of 9
iNeuron Intelligence Pvt Ltd

affect any other copy that uses the object. Deep copy makes execu8on
of the program slower due to making certain copies for each object
that is been called.

Q12. How is Mul8threading achieved in Python?

Ans:

1. Python has a mul8-threading package but if you want to mul8-


thread to speed your code up, then it’s usually not a good idea
to use it.
2. Python has a construct called the Global Interpreter Lock (GIL).
The GIL makes sure that only one of your ‘threads’ can execute
at any one 8me. A thread acquires the GIL, does a liXle work,
then passes the GIL onto the next thread.
3. This happens very quickly so to the human eye it may seem like
your threads are execu8ng in parallel, but they are really just
taking turns using the same CPU core.
4. All this GIL passing adds overhead to execu8on. This means that
if you want to make your code run faster then using the
threading package oden isn’t a good idea.

Q13. What is the process of compila8on and linking in python?

Ans: The compiling and linking allow the new extensions to be


compiled properly without any error and the linking can be done only
when it passes the compiled procedure. If the dynamic loading is used
then it depends on the style that is being provided with the system.
The python interpreter can be used to provide the dynamic loading of
the configura8on setup files and will rebuild the interpreter.

Page 6 of 9
iNeuron Intelligence Pvt Ltd

The steps that are required in this as:

1. Create a file with any name and in any language that is supported
by the compiler of your system. For example file.c or file.cpp
2. Place this file in the Modules/ directory of the distribu8on which
is gepng used.
3. Add a line in the file Setup. Local that is present in the Modules/
directory.
4. Run the file using spam file.o
5. Ader a successful run of this rebuild the interpreter by using the
make command on the top-level directory.
6. If the file is changed then run rebuildMakefile by using the
command as ‘make Makefile’.

Q14. What are Python libraries? Name a few of them.

Ans- Python libraries are a collec8on of Python packages. Some of the


majorly used python libraries are – Numpy, Pandas, Matplotlib, Scikit-
learn and many more.

Q15. What is split used for?

Ans- The split() method is used to separate a given String in Python.

Q16. What is the usage of help () and dir () func8on in Python?

Ans: Help() and dir() both func8ons are accessible from the Python
interpreter and used for viewing a consolidated dump of built-in
func8ons.
Page 7 of 9
iNeuron Intelligence Pvt Ltd

Q17. Whenever Python exits, why isn’t all the memory de-allocated?

Ans:

4. Whenever Python exits, especially those Python modules which


are having circular references to other objects or the objects that
are referenced from the global namespaces are not always de-
allocated or freed.
5. It is impossible to de-allocate those por8ons of memory that are
reserved by the C library.
6. On exit, because of having its own efficient clean up mechanism,
Python would try to de-allocate/destroy every other object.

Q18. What does this mean: *args, **kwargs? And why would we use
it?

Ans: We use *args when we aren’t sure how many arguments are
going to be passed to a func8on, or if we want to pass a stored list or
tuple of arguments to a func8on. **kwargs is used when we don’t
know how many keyword arguments will be passed to a func8on, or it
can be used to pass the values of a dic8onary as keyword arguments.
The iden8fiers args and kwargs are a conven8on, you could also use
*bob and **billy but that would not be wise.

Q19. Explain split(), sub(), subn() methods of “re” module in Python.

Ans: To modify the strings, Python’s “re” module is providing 3


methods. They are:
Page 8 of 9
iNeuron Intelligence Pvt Ltd

• split() – uses a regex paXern to “split” a given string into a list.


• sub() – finds all substrings where the regex paXern matches and
then replace them with a different string
• subn() – it is similar to sub() and also returns the new string along
with the no. of replacements.

Q20. What are nega8ve indexes and why are they used?

Ans: The sequences in Python are indexed and it consists of the


posi8ve as well as nega8ve numbers. The numbers that are posi8ve
uses ‘0’ that is uses as first index and ‘1’ as the second index and the
process goes on like that.

The index for the nega8ve number starts from ‘-1’ that represents the
last index in the sequence and ‘-2’ as the penul8mate index and the
sequence carries forward like the posi8ve number.

The nega8ve index is used to remove any new-line spaces from the
string and allow the string to except the last character that is given as
S[:-1]. The nega8ve index is also used to show the index to represent
the string in correct order.

Page 9 of 9
iNeuron Intelligence Pvt Ltd

Q1. What are Python packages?

Ans: Python packages are namespaces containing mul;ple modules.

Q2.How can files be deleted in Python?

Ans: To delete a file in Python, you need to import the OS Module.


AGer that, you need to use the os. remove() func;on.

Q3. What advantages do NumPy arrays offer over (nested) Python


lists?

Ans:

1. Python’s lists are efficient general-purpose containers. They


support (fairly) efficient inser;on, dele;on, appending, and
concatena;on, and Python’s list comprehensions make them
easy to construct and manipulate.
2. They have certain limita;ons: they don’t support “vectorized”
opera;ons like elementwise addi;on and mul;plica;on, and the
fact that they can contain objects of differing types mean that
Python must store type informa;on for every element, and must
execute type dispatching code when opera;ng on each element.
3. NumPy is not just more efficient; it is also more convenient. You
get a lot of vector and matrix opera;ons for free, which
some;mes allow one to avoid unnecessary work. And they are
also efficiently implemented.

Page 2 of 10
iNeuron Intelligence Pvt Ltd

4. NumPy array is faster and You get a lot built in with NumPy, FFTs,
convolu;ons, fast searching, basic sta;s;cs, linear
algebra, histograms, etc.

Q53. How to remove values to a python array?

Ans: Array elements can be removed


using pop() or remove() method. The difference between these
two func;ons is that the former returns the deleted value
whereas the la\er does not.

Q4. Does Python have OOps concepts?

Ans: Python is an object-oriented programming language. This means


that any program can be solved in python by crea;ng an object
model. However, Python can be treated as a procedural as well as
structural language.

Q5. What is the difference between deep and shallow copy?

Ans: Shallow copy is used when a new instance type gets created and
it keeps the values that are copied in the new instance. Shallow copy
is used to copy the reference pointers just like it copies the values.
These references point to the original objects and the changes made

Page 3 of 10
iNeuron Intelligence Pvt Ltd

in any member of the class will also affect the original copy of
it. Shallow copy allows faster execu;on of the program and it depends
on the size of the data that is used.

Deep copy is used to store the values that are already copied. Deep
copy doesn’t copy the reference pointers to the objects. It makes the
reference to an object and the new object that is pointed by some
other object gets stored. The changes made in the original copy won’t
affect any other copy that uses the object. Deep copy makes execu;on
of the program slower due to making certain copies for each object
that is been called.

Q6. How is Mul;threading achieved in Python?

Ans:

1. Python has a mul;-threading package but if you want to mul;-


thread to speed your code up, then it’s usually not a good idea
to use it.
2. Python has a construct called the Global Interpreter Lock (GIL).
The GIL makes sure that only one of your ‘threads’ can execute
at any one ;me. A thread acquires the GIL, does a li\le work,
then passes the GIL onto the next thread.
3. This happens very quickly so to the human eye it may seem like
your threads are execu;ng in parallel, but they are really just
taking turns using the same CPU core.
4. All this GIL passing adds overhead to execu;on. This means that
if you want to make your code run faster then using the
threading package oGen isn’t a good idea.

Page 4 of 10
iNeuron Intelligence Pvt Ltd

Q7. What is the process of compila;on and linking in python?

Ans: The compiling and linking allow the new extensions to be


compiled properly without any error and the linking can be done only
when it passes the compiled procedure. If the dynamic loading is used
then it depends on the style that is being provided with the system.
The python interpreter can be used to provide the dynamic loading of
the configura;on setup files and will rebuild the interpreter.

The steps that are required in this as:

1. Create a file with any name and in any language that is supported
by the compiler of your system. For example file.c or file.cpp
2. Place this file in the Modules/ directory of the distribu;on which
is gehng used.
3. Add a line in the file Setup. Local that is present in the Modules/
directory.
4. Run the file using spam file.o
5. AGer a successful run of this rebuild the interpreter by using the
make command on the top-level directory.
6. If the file is changed then run rebuildMakefile by using the
command as ‘make Makefile’.

Q8. What are Python libraries? Name a few of them.

Ans- Python libraries are a collec;on of Python packages. Some of the


majorly used python libraries are – Numpy, Pandas, Matplotlib, Scikit-
learn and many more.

Page 5 of 10
iNeuron Intelligence Pvt Ltd

Q9. What is split used for?

Ans- The split() method is used to separate a given String in Python.

Q10. What is the difference between range & xrange?

Func;ons in Python, range() and xrange(), are used to iterate inside a


for loop for a fixed number of ;mes. Func;onality-wise, both these
func;ons are the same. The difference comes when talking
about the Python version support for these func;ons and their return
values.

Q11. What is pickling and unpickling?

The Pickle module accepts the Python object and converts it into a
string representa;on and stores it into a file by using the dump
func;on. This process is called pickling. On the other hand, the process
of retrieving the original Python objects from the string representa;on
is called unpickling.

Q12. What do you understand by the word Tkinter?

Ans- Tkinter is a built-in Python module that is used to create GUI


applica;ons and it is Python’s standard toolkit for GUI development.

Page 6 of 10
iNeuron Intelligence Pvt Ltd

Tkinter comes pre-loaded with Python so there is no separate


installa;on needed. You can start using it by impor;ng it in your script.

Q13. Is Python fully object oriented?

Python does follow an object-oriented programming paradigm and


has all the basic OOPs concepts such as inheritance, polymorphism,
and more, with the excep;on of access specifiers. Python doesn’t
support strong encapsula;on (adding a private keyword before data
members). Although, it has a conven;on that can be used for data
hiding, i.e., prefixing a data member with two underscores.

Q14. What do file-related modules in Python do? Can you name


some file-related modules in Python?

Python comes with some file-related modules that have func;ons to


manipulate text files and binary files in a file system. These modules
can be used to create text or binary files, update content by carrying
out opera;ons like copy, delete, and more.

Some file-related modules are os, os.path, and shu;l.os. The os.path
module has func;ons to access the file system, while the shu;l.os
module can be used to copy or delete files.

Page 7 of 10
iNeuron Intelligence Pvt Ltd

Q15. Explain the use of the 'with' statement and its syntax?

In Python, using the ‘with’ statement, we can open a file and close it
as soon as the block of code, where ‘with’ is used, exits. In this way,
we can opt for not using the close() method.

Q16. What does *args and **kwargs mean in Python?

Ans- *args: It is used to pass mul;ple arguments in a func;on.

**kwargs: It is used to pass mul;ple keyworded arguments in a


func;on in Python.

Q17. How will you remove duplicate elements from a list?

To remove duplicate elements from the list we use the set() func;on.

Consider the below example:

demo_list = [5, 4, 4, 6, 8, 12, 12, 1, 5]

unique_list = list(set(demo_list))

output = [1, 5, 6, 8, 12]


Page 8 of 10
iNeuron Intelligence Pvt Ltd

Q18. How can files be deleted in Python?

Ans- You need to import the OS Module and use os.remove()


func;on for dele;ng a file in python.

consider the code below:

import os

os.remove("file_name.txt")

Q19. How will you read a random line in a file?

We can read a random line in a file using the random module.

For example:

import random

def read_random(fname):

lines = open(fname).read().splitlines()

return random.choice(lines)

print(read_random('hello.txt'))

Page 9 of 10
iNeuron Intelligence Pvt Ltd

Q20. Write a Python program to count the total number of lines in a


text file?

Refer the code below to count the total number of lines in a text file-

def file_count(fname):

with open(fname) as f:

for i, _ in enumerate(f):

pass

return i + 1

print("Total number of lines in the text file:",

file_count("file.txt"))

Page 10 of 10
iNeuron Intelligence Pvt Ltd

Q1. What is the purpose of “is”, “not” and “in” operators?

Operators are referred to as special func:ons that take one or more


values (operands) and produce a corresponding result.

• is: returns the true value when both the operands are
true (Example: “x” is ‘x’)
• not: returns the inverse of the boolean value based upon
the operands (example:”1” returns “0” and vice-versa.

In: helps to check if the element is present in a given Sequence or not.

Q2. Whenever Python exits, why isn’t all the memory de-allocated?

• Whenever Python exits, especially those Python modules


which are having circular references to other objects or the
objects that are referenced from the global namespaces, the
memory is not always de-allocated or freed.
• It is not possible to de-allocate those por:ons of memory
that are reserved by the C library.
• On exit, because of having its own efficient clean up
mechanism, Python will try to de-allocate every object.

Q3. How to remove values to a python array?

Elements can be removed from a python array by using pop() or


remove() methods.

Page 2 of 13
iNeuron Intelligence Pvt Ltd

pop(): This func:on will return the removed element .

remove():It will not return the removed element.

Consider the below example :

x=arr.array('d', [8.1, 2.4, 6.8, 1.1, 7.7, 1.2, 3.6])

print(x.pop())

print(x.pop(3))

x.remove(8.1)

print(x)

Q4. Why would you use NumPy arrays instead of lists in Python?

NumPy arrays provide users with three main advantages as shown


below:

• NumPy arrays consume a lot less memory, thereby making


the code more efficient.

Page 3 of 13
iNeuron Intelligence Pvt Ltd

• NumPy arrays execute faster and do not add heavy


processing to the run:me.
• NumPy has a highly readable syntax, making it easy and
convenient for programmers.

Q5. What is polymorphism in Python?

Polymorphism is the ability of the code to take mul:ple forms. Let’s


say, if the parent class has a method named XYZ then the child class
can also have a method with the same name XYZ having its own
variables and parameters.

Q6. Define encapsula:on in Python?

Encapsula:on in Python refers to the process of wrapping up the


variables and different func:ons into a single en:ty or
capsule. The Python class is the best example of encapsula:on in
python.

Q7. What advantages do NumPy arrays offer over (nested) Python


lists?

Nested Lists:

• Python lists are efficient, general-purpose containers that


support efficient opera:ons like
inser:on, appending, dele:on and concatena:on.
Page 4 of 13
iNeuron Intelligence Pvt Ltd

• The limita:ons of lists are that they don’t support


“vectorized” opera:ons like element wise addi:on and
mul:plica:on, and the fact that they can contain objects of
differing types means that Python must store the data type
informa:on for every element, and must execute type
dispatching code when opera:ng on each element.

Numpy:

• NumPy is more efficient and more convenient as you get a


lot of vector and matrix opera:ons for free, this helps avoid
unnecessary work and complexity of the code. NumPy is
also efficiently implemented when compared to nested lists.
• NumPy array is faster and contains a lot of built-in func:ons
which will help in FFTs, convolu:ons, fast searching, linear
algebra, basic sta:s:cs, histograms, etc.

Q8. What is the lambda func:on in Python?

A lambda func:on is an anonymous func:on (a func:on that does


not have a name) in Python. To define anonymous func:ons, we use
the ‘lambda’ keyword instead of the ‘def’ keyword, hence the name
‘lambda func:on’. Lambda func:ons can have any number of
arguments but only one statement.

For example:
Page 5 of 13
iNeuron Intelligence Pvt Ltd

l = lambda (x,y) : x*y

print(a(5, 6))

Q9. What is the difference between append() and extend() methods?

Both append() and extend() methods are methods used to add


elements at the end of a list.

The primary differen:a:on between the append() and extend()


methods in Python is that append() is used to add a single element to
the end of a list. In contrast, open () is used to append mul:ple aspects,
such as another list or an iterable, to the end of a list.

Q10. How does Python Flask handle database requests?

Ans- Flask supports a database-powered applica:on (RDBS). Such a


system requires crea:ng a schema, which needs piping the schema.
SQL file into the sqlite3 command. Python developers need to install
the sqlite3 command to create or ini:ate the database in Flask.

Flask allows to request for a database in three ways:

• before_request(): They are called before a request and pass


no arguments.
Page 6 of 13
iNeuron Intelligence Pvt Ltd

• aoer_request(): They are called aoer a request and pass the


response that will be sent to the client.
• teardown_request(): They are called in a situa:on when an
excep:on is raised and responses are not guaranteed. They
are called aoer the response has been constructed. They are
not allowed to modify the request, and their values are
ignored.

Q11. How is mul:-threading achieved in Python?

Ans- Python has a mul:-threading package but commonly not


considered a good prac:ce to use it as it results in increased code
execu:on :me.

• Python has a constructor called the Global Interpreter Lock


(GIL). The GIL ensures that only one of your ‘threads’ can
execute at one :me. The process makes sure that a thread
acquires the GIL, does work, then passes the GIL onto the
next thread.
• This occurs almost instantaneously, giving the illusion of
parallel execu:on to the human observer. However, the
threads execute sequen:ally, taking turns u:lizing the same
CPU core.

Page 7 of 13
iNeuron Intelligence Pvt Ltd

Q12. What is slicing in Python?

Ans- Slicing is a technique employed to extract a specific range of


elements from sequen:al data types, such as lists, strings, and tuples.
Slicing is beneficial and easy to extract out elements. It requires a :
(colon) which separates the start index and end index of the field. All
the data sequence types, list or tuple, allows users to use slicing to get
the needed elements. Although we can get elements by specifying an
index, we get only a single element. Whereas, using slicing, we can get
a group or appropriate range of needed elements.

Q13. What is func:onal programming? Does Python follow a


func:onal programming style? If yes, list a few methods to
implement func:onally oriented programming in Python.

Func:onal programming is a coding style where the main source of


logic in a program comes from func:ons.

Incorpora:ng func:onal programming in our codes means wri:ng


pure func:ons.

Pure func:ons are func:ons that cause lirle or no changes outside the
scope of the func:on. These changes are referred to as side effects. To
reduce side effects, pure func:ons are used, which makes the code
easy-to-follow, test, or debug.

Page 8 of 13
iNeuron Intelligence Pvt Ltd

Q14. What is monkey patching in Python?

Ans - Monkey patching is the term used to denote modifica:ons that


are done to a class or a module during run:me. This can only be
done as Python supports changes in the behaviour of the program
while being executed.

The following is an example, deno:ng monkey patching in Python:

# monkeyy.py

class X:

def func(self):

print("func() is being called")

Q15. What is pandas?

Pandas is an open source python library which supports data


structures for data based opera:ons associated with data analyzing
and data manipula:on . Pandas, with its rich sets of features, fits in
every role of data opera:on, whether it be related to implemen:ng
Page 9 of 13
iNeuron Intelligence Pvt Ltd

different algorithms or for solving complex business problems. Pandas


helps to deal with a number of files in performing certain opera:ons
on the data stored by files.

Q16. What are dataframes?

Ans- A dataframes refers to a two dimensional mutable data structure


or data aligned in the tabular form with labelled axes(rows and
column).

Syntax:

pandas.DataFrame( data, index, columns, dtype)

data: It refers to various forms like ndarray, series, map, lists, dict,
constants and can take other DataFrame as Input.

index: This argument is op:onal as the index for row labels will be
automa:cally taken care of by pandas library.

columns: This argument is op:onal as the index for column labels will
be automa:cally taken care of by pandas library.

Dtype: refers to the data type of each column.

Page 10 of 13
iNeuron Intelligence Pvt Ltd

Q17. What is regression?

Regression is termed as a supervised machine learning algorithm


technique which is used to find the correla:on between variables. It
helps predict the value of the dependent variable(y) based upon the
independent variable (x). It is mainly used for predic:on, :me series
modelling , forecas:ng, and determining the causal-effect
rela:onship between variables.

Scikit library is used in python to implement the regression and all


machine learning algorithms.

There are two different types of regression algorithms in machine


learning :

Linear Regression: Used when the variables are con:nuous and


numeric in nature.

Logis:c Regression: Used when the variables are con:nuous and


categorical in nature.

Page 11 of 13
iNeuron Intelligence Pvt Ltd

Q18. Write a program in Python to check if a number is prime?

Ans-

Q19. Write a Program to print ASCII Value of a character in python?

Ans-

Q20. Write a sor:ng algorithm for a numerical dataset in Python.

Ans- my_list = ["8", "4", "3", "6", "2"]

my_list = [int(i) for i in list]

Page 12 of 13
iNeuron Intelligence Pvt Ltd

my_list.sort()

print (my_list)

Page 13 of 13
iNeuron Intelligence Pvt Ltd

Q1. What are the different types of func6on in Python?


Ans- a) Built-in func6on
b) User defined func6on

Q2. Why are func6ons required?


Ans- Many 6mes in a program a certain set of instruc6ons may be
called again and again. Instead of wri6ng same piece of code
whether it is required it is beHer to define a func6on and place the
code in it. This func6on can be called whenever there is ned. This
save 6me effort and program can be developed easily. Func6ons help
in organizing coding work and tes6ng of code also becomes easy.

Q3. What is a func6on header?


Ans- First line of func6on defini6on that starts with def and ends
with a colon(:) is called a func6on header.

Q4. When does a func6on execute?


Ans- A func6on executes when a call is made to it. It can be called
directly from Python prompt or from another func6on.

Q5. What is a parameter? What is the difference between a


parameter and argument?
Ans- A parameter is a variable that is defined in a func6on defini6on
whereas an argument is an actual value that is passed on to the
func6on. The data carried in the argument is passed on to the
parameters.

Q6. Why do we use the Python startup environment variable?

Page 2 of 5
iNeuron Intelligence Pvt Ltd

Ans- The variable consists of the path in which the ini6aliza6on file
carrying the Python source code can be executed. This is needed to
start the interpreter.

Q7. What is the Pythoncaseok environment variable?


Ans- The Pythoncaseok environment variable is applied in Windows
with the purpose of direc6ng Python to find the first case-insensi6ve
match in an import statement.

Q8. What are posi6ve and nega6ve indices?


Ans- Posi6ve indices are applied when the search begins from leW to
right. In nega6ve indices, the search begins from right to leW. For
example, in the array list of size n the posi6ve index, the first index is
0, then comes 1, and un6l the last index is n-1. However, in the
nega6ve index, the first index is -n, then -(n-1) un6l the last index -1.

Q9. What is the permiHed length of the iden6fier?


Ans- The length of the iden6fier in Python can be of any length. The
longest iden6fier will be from PEP – 8 and PEP – 20.

Q10. What does the method object() do?


Ans- The method returns a featureless object that is the base for all
classes. This method does not take any parameters.

Q11. What is pep 8?


Ans- Python Enhancement Proposal, or pep 8, is a set of rules that
specify how to format Python code for maximum readability.

Q12. What is namespace in Python?


Ans- A namespace is a naming system used to make sure names are
unique to avoid naming conflicts.

Page 3 of 5
iNeuron Intelligence Pvt Ltd

Q13. Is indenta6on necessary in Python?


Ans- Indenta6on is required in Python. If not done properly, the code
is not executed properly and might throw errors. Indenta6on is
usually done using four space characters.

Q14. Define self in Python.


Ans- Self is an instance of a class or an object in Python. It is included
as the first parameter. It helps differen6ate between the methods
and aHributes of a class with local variables.

Q15. What is the Pass statement?


Ans- A Pass statement in Python is used when we cannot decide
what to do in our code, but we must type something to make it
syntac6cally correct.

Q16. What are the limita6ons of Python?


Ans- There are limita6ons to Python, which include the following:

It has design restric6ons.


It is slower when compared with C and C++ or Java.
It is inefficient for mobile compu6ng.
It consists of an underdeveloped database access layer

Q17. Why do we need a con6nue?


Ans- A con6nue helps control the Python loop by making jumps to
the next itera6on of the loop without exhaus6ng it.

Q18. Can we use a break and con6nue together in Python? How?

Page 4 of 5
iNeuron Intelligence Pvt Ltd

Ans- Break and con6nue can be used together in Python. The break
will stop the current loop from execu6on, while the jump will take it
to another loop.

Q19. Does Python support an intrinsic do-while loop?


Ans- No, Python does not support an intrinsic do-while loop.

Q20. What are rela6onal operators, assignment operators, and


membership operators?
Ans- The purpose of rela6onal operators is to compare values.
The assignment operators in Python can help in combining all the
arithme6c operators with the assignment symbol.
Membership operators in Python with the purpose of valida6ng the
membership of a value in a sequence.

Page 5 of 5
iNeuron Intelligence Pvt Ltd

Q1. How are iden.ty operators different from membership


operators?
Ans- Unlike membership operators, iden.ty operators compare the
values to find out if they have the same value or not.

Q2. What are Python decorators?


Ans- A specific change made in Python syntax to alter the func.ons
easily is termed a Python decorator.

Q3. Differen.ate between list and tuple.


Ans- Tuple is not mutable. It can be hashed e.g. key for dic.onaries.
On the other hand, lists are mutable.

Q4. Describe mul.threading in Python.


Ans- Using Mul.threading to speed up the code is not the go-to
op.on, even though Python comes with a mul.-threading package.

The package has the GIL or Global Interpreter Lock, which is a


construct. It ensures that only one of the threads executes at any
given .me. A thread acquires the GIL and then performs work before
passing it to the next thread.

This happens so fast that to a user, it seems that threads are


execu.ng in parallel. Obviously, this is not the case, as they are just
taking turns while using the same CPU core. GIL passing adds to the
overall overhead of the execu.on.

As such, if you intend to use the threading package to speed up the


execu.on, using the package is not recommended.

Q5. Draw a comparison between the range and xrange in Python.

Page 2 of 9
iNeuron Intelligence Pvt Ltd

Ans- In terms of func.onality, both range and xrange are iden.cal.


Both allow for genera.ng a list of integers. The main difference
between the two is that while range returns a Python list object,
xrange returns an xrange object.

Xrange is not able to generate a sta.c list at run.me the way range
does. On the contrary, it creates values along with the requirements
via a special technique called yielding. It is used with a type of object
known as a generator.

If you have an enormous range for which you need to generate a list,
then xrange is the func.on to opt for. This is especially relevant for
scenarios dealing with a memory-sensi.ve system, such as a
smartphone.

Q6. Explain Inheritance.


Ans- Inheritance enables a class to acquire all members of another
class. These members can be aYributes, methods, or both. By
providing reusability, inheritance makes it easier to create as well as
maintain an applica.on.

The class which acquires is known as the child class or the derived
class. The one that it acquires from is known as the superclass, base
class, or parent class. There are 4 forms of inheritance supported by
Python:

Single inheritance: A single derived class acquires members from one


superclass.
Mul.-Level inheritance: At least 2 different derived classes acquire
members from two dis.nct base classes.

Page 3 of 9
iNeuron Intelligence Pvt Ltd

Hierarchical inheritance: A number of child classes acquire members


from one superclass
Mul.ple inheritance: A derived class acquires members from several
super classes.

Q7. What is the difference between deep copy and shallow copy?
Ans- We use a shallow copy when a new instance type gets created.
It keeps the values that are copied in the new instance. Just like it
copies the values, the shallow copy also copies the reference
pointers.

Reference points copied in the shallow copy reference to the original


objects. Any changes made in any member of the class affect the
original copy of the same. Shallow copy enables faster execu.on of
the program.

Deep copy is used for storing values that are already copied. Unlike
shallow copy, it doesn’t copy the reference pointers to the objects.
Deep copy makes the reference to an object in addi.on to storing the
new object that is pointed by some other object.

Changes made to the original copy will not affect any other copy that
makes use of the referenced or stored object. Contrary to the shallow
copy, deep copy makes the execu.on of a program slower. This is due
to the fact that it makes some copies for each object that is called.

Q8. How do you dis.nguish between NumPy and SciPy?


Ans- Typically, NumPy contains nothing but the array data type and
the most basic opera.ons, such as basic element-wise func.ons,
indexing, reshaping, and sor.ng. All the numerical code resides in
SciPy.

Page 4 of 9
iNeuron Intelligence Pvt Ltd

As one of NumPy’s most important goals is compa.bility, the library


tries to retain all features supported by either of its predecessors.
Hence, NumPy contains a few linear algebra func.ons despite the
fact that these more appropriately belong to the SciPy library.

SciPy contains fully-featured versions of the linear algebra modules


available to NumPy in addi.on to several other numerical algorithms.

Q9. What is the output of the following code?


A0 = dict(zip(('a', 'b', 'c', 'd', 'e'),(1,2,3,4,5)))
A1 = range(10)A2 = sorted([i for i in A1 if i in A0])
A3 = sorted([A0[s] for s in A0])
A4 = [i for i in A1 if i in A3]
A5 =
A6 = [[i, i*i] for i in A1]
print(A0,A1,A2,A3,A4,A5,A6)
A0 = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} # The order may vary

A1 = range(0, 10)

A2 = []

A3 = [1, 2, 3, 4, 5]

A4 = [1, 2, 3, 4, 5]

A5 =

Page 5 of 9
iNeuron Intelligence Pvt Ltd

A6 = [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64],
[9, 81]]

Q10. Explain dic.onaries with an example.


A dic.onary in the Python programming language is an unordered
collec.on of data values such as a map. The dic.onary holds the key:
value pair. This helps define a one-to-one rela.onship between keys
and values. Indexed by keys, a typical dic.onary contains a pair of
keys and corresponding values.

Let us take an example with three keys, namely website, language,


and offering. Their corresponding values are hackr.io, Python, and
Tutorials. The code for would be:

dict={‘Website’:‘hackr.io’,‘Language’:‘Python’:‘Offering’:‘Tutorials’}
print dict[Website] #Prints hackr.io
print dict[Language] #Prints Python
print dict[Offering] #Prints Tutorials

Q11. Python supports nega.ve indexes. What are they and why are
they used?
The sequences in Python are indexed. It consists of posi.ve and
nega.ve numbers. Posi.ve numbers use 0 as the first index, 1 as the
second index, and so on. Hence, any index for a posi.ve number n is
n-1.

Unlike posi.ve numbers, index numbering for nega.ve numbers


starts from -1, and it represents the last index in the sequence.
Likewise, -2 represents the penul.mate index. These are known as
nega.ve indexes. Nega.ve indexes are used for:

Page 6 of 9
iNeuron Intelligence Pvt Ltd

Removing any new-line spaces from the string, thus allowing the
string to except the last character, represented as S[:-1]
Showing the index to represent the string in the correct order.

Q12. What is the output of the following code?


Ans- try: if '1' != 1:
raise "someError"
else: print("someError has not occurred")
except "someError": pr
int ("someError has occurred")
The output of the program will be “invalid code.” This is because a
new excep.on class must inherit from a Base Excep.on.

Q13. Explain the process of compila.on and linking.


Ans- In order to compile new extensions without any error, compiling
and linking is used in Python. Linking ini.ates only and only when the
compila.on is complete.

In the case of dynamic loading, the process of compila.on and linking


depends on the style that is provided with the concerned system. In
order to provide dynamic loading of the configura.on setup files and
rebuild the interpreter, the Python interpreter is used.

Q14. What is Flask and what are the benefits of using it?
Ans- Flask is a web microframework for Python with Jinja2 and
Werkzeug as its dependencies. As such, it has some notable
advantages:

Page 7 of 9
iNeuron Intelligence Pvt Ltd

Flask has liYle to no dependencies on external libraries.


Because there is a liYle external dependency to update and fewer
security bugs, the web microframework is lightweight.
It has an inbuilt development server and a fast debugger.

Q15. What is the map() func.on used for?


Ans- The map() func.on applies a given func.on to each item of an
iterable. It then returns a list of the results. The value returned from
the map() func.on can then be passed on to func.ons to the likes of
the list() and set().

Typically, the given func.on is the first argument, and the iterable is
available as the second argument to a map() func.on. Several tables
are given if the func.on takes in more than one argument.

Q16. Whenever Python exits, not all the memory is deallocated. Why
is it so?
Ans- Upon exi.ng, Python’s built-in effec.ve cleanup mechanism
comes into play and tries to deallocate or destroy every other object.
However, Python modules that have circular references to other
objects, or the objects that are referenced from the global
namespaces, aren’t always deallocated or destroyed.

This is because it is not possible to deallocate those por.ons of the


memory that are reserved by the C library.

Q17. Write a program in Python for geung indices of N maximum


values in a NumPy array.

Page 8 of 9
iNeuron Intelligence Pvt Ltd

import numpy as np
arr = np.array([1, 3, 2, 4, 5])
print(arr.argsort()[-3:][::-1])
Output:
[4 3 1]

Q18. How is memory managed in Python?


Ans- Python private heap space takes the place of memory
management in Python. It contains all Python objects and data
structures. The interpreter is responsible to take care of this private
heap, and the programmer does not have access to it. The Python
memory manager is responsible for the alloca.on of Python heap
space for Python objects. The programmer may access some tools for
the code with the help of the core API. Python also provides an
inbuilt garbage collector, which recycles all the unused memory and
frees the memory, and makes it available to heap space.

Q19. What is the lambda func.on?


Ans- A lambda func.on is an anonymous func.on. This func.on can
have only one statement but can have any number of parameters.

a = lambda x,y : x+y


print(a(5, 6))

Q20. How are arguments passed in Python? By value or by


reference?
Everything in Python is an object, and all variables hold references to
the object. The reference values are according to the func.ons; as a
result, the value of the reference cannot be changed.

Page 9 of 9
iNeuron Intelligence Pvt Ltd

Q1. What are the built-in types provided by Python?


Ans- Mutable built-in types:

Lists
Sets
Dic@onaries
Immutable built-in types:

Strings
Tuples
Numbers

Q2. What are Python modules?


Ans- A file containing Python code, like func@ons and variables, is a
Python module. A Python module is an executable file with a .py
extension. Some built-in modules are:

os
sys
math
random
data @me
JSON

Q3. What is the // operator? What is its use?


The // is a floor division operator used for dividing two operands with
the result as a quo@ent displaying digits before the decimal point. For
instance, 10//5 = 2 and 10.0//5.0 = 2.0.

Page 2 of 8
iNeuron Intelligence Pvt Ltd

Q4. What is the split func@on used for?


The split func@on breaks the string into shorter strings using the
defined separator. It returns the list of all the words present in the
string.

Q5. Explain the Dogpile effect.


The dogpile effect is when the cache expires, and websites are hit by
mul@ple requests made by the client at the same @me. Using a
semaphore lock prevents the Dogpile effect. In this system, when a
value expires, the first process acquires the lock and starts genera@ng
a new value.

Q6. What is a pass in Python?


Ans- The no-opera@on Python statement refers to a pass. It is a
placeholder in the compound statement, where there should have a
blank le\ or nothing wri]en there.

Q7. What is [::-1} used for?


Ans- [::-1} reverses the order of an array or a sequence. However, the
original array or the list remains unchanged.

import array as arr


Num_Array=arr.array('k',[1,2,3,4,5])
Num_Array[::-1]

Q8. How do you capitalize the first le]er of string?


Ans- The capitalize() method capitalizes the first le]er of the string,
and if the le]er is already capitalized it returns the original string

Page 3 of 8
iNeuron Intelligence Pvt Ltd

Q9. What are the is, not, and in operators?


Ans- Operators are func@ons that take two or more values and return
the corresponding result.

is: returns true when two operands are true


not: returns inverse of a boolean value
in: checks if some element is present in some sequence.

Q10. How are modules imported in Python?


Ans- Modules are imported using the import keyword in either of the
following three ways:

import array
import array as arr
from array import *

Q11.How would you convert a list to an array?


Ans- During programming, there will be instances when you will need
to convert exis@ng lists to arrays in order to perform certain
opera@ons on them (arrays enable mathema@cal opera@ons to be
performed on them in ways that lists do not).

Here we’ll be using numpy.array(). This func@on of the numpy library


takes a list as an argument and returns an array that contains all the
elements of the list.

Q12. How is memory managed in Python?


Ans- Memory management in python is managed by Python private
heap space. All Python objects and data structures are located in a

Page 4 of 8
iNeuron Intelligence Pvt Ltd

private heap. The programmer does not have access to this private
heap. The python interpreter takes care of this instead.
The alloca@on of heap space for Python objects is done by Python’s
memory manager. The core API gives access to some tools for the
programmer to code.
Python also has an inbuilt garbage collector, which recycles all the
unused memory and so that it can be made available to the heap
space.

Q13. How do you achieve mul@threading in Python?


Ans- Python has a mul@-threading package but if you want to mul@-
thread to speed your code up, then it’s usually not a good idea to use
it.
Python has a construct called the Global Interpreter Lock (GIL). The
GIL makes sure that only one of your ‘threads’ can execute at any one
@me. A thread acquires the GIL, does a li]le work, then passes the
GIL onto the next thread.
This happens very quickly so to the human eye it may seem like your
threads are execu@ng in parallel, but they are really just taking turns
using the same CPU core.
All this GIL passing adds overhead to execu@on. This means that if
you want to make your code run faster then using the threading
package o\en isn’t a good idea.

Q14. What is monkey patching?


Ans- In Python, the term monkey patch only refers to dynamic
modifica@ons of a class or module at run-@me.

Page 5 of 8
iNeuron Intelligence Pvt Ltd

Q15. What is pickling and unpickling?


Ans- Pickle module accepts any Python object and converts it into a
string representa@on and dumps it into a file by using dump func@on,
this process is called pickling. While the process of retrieving original
Python objects from the stored string representa@on is called
unpickling.

Q16. What advantages do NumPy arrays offer over (nested) Python


lists?
Ans- Python’s lists are efficient general-purpose containers. They
support (fairly) efficient inser@on, dele@on, appending, and
concatena@on, and Python’s list comprehensions make them easy to
construct and manipulate.
They have certain limita@ons: they don’t support “vectorized”
opera@ons like elementwise addi@on and mul@plica@on, and the fact
that they can contain objects of differing types mean that Python
must store type informa@on for every element, and must execute
type dispatching code when opera@ng on each element.
NumPy is not just more efficient; it is also more convenient. You get a
lot of vector and matrix opera@ons for free, which some@mes allow
one to avoid unnecessary work. And they are also efficiently
implemented.
NumPy array is faster and You get a lot built in with NumPy, FFTs,
convolu@ons, fast searching, basic sta@s@cs, linear algebra,
histograms, etc.

Q17. How would you make a deep copy in Python?


Ans- A deep copy refers to cloning an object. When we use the =
operator, we are not cloning the object; instead, we reference our
variable to the same object (a.k.a. shallow copy).

Page 6 of 8
iNeuron Intelligence Pvt Ltd

This means that changing one variable’s value affects the other
variable’s value because they are referring (or poin@ng) to the same
object. This difference between a shallow and a deep copy is only
applicable to objects that contain other objects, like lists and
instances of a class.

Q18. What is a Python Docstring?


Ans- The Python docstrings provide a suitable way of associa@ng
documenta@on with:

Python modules
Python func@ons
Python classes
It is a specified document for the wri]en code. Unlike conven@onal
code comments, the doctoring should describe what a func@on does,
not how it works.

Q19. What is defaultdict in Python?


Ans- The Python dic@onary, dict, contains words and meanings as
well as key-value pairs of any data type. The defaultdict is another
subdivision of the built-in dict class.

How is defaultdict different?

The defaultdict is a subdivision of the dict class. Its importance lies in


the fact that it allows each new key to be given a default value based
on the type of dic@onary being created.

A defaultdict can be created by giving its declara@on, an argument


that can have three values; list, set or int. According to the specified

Page 7 of 8
iNeuron Intelligence Pvt Ltd

data type, the dic@onary is created and when any key, that does not
exist in the defaultdict is added or accessed, it is assigned a default
value as opposed to giving a Key Error.

Q20. What is Flask?


Ans. Flask (source code) is a Python micro web framework and it
does not require par@cular tools or libraries. It is used for deploying
python code into web apps.

Page 8 of 8
iNeuron Intelligence Pvt Ltd

Q1. How will you perform sta4c analysis in a Python applica4on or


find bugs?
Ans- PyChecker can be helpful as a sta4c analyser to iden4fy the bugs
in the Python project. This also helps to find out the complexity-
related bugs. Pylint is another tool that helps check if the Python
module is at par with the coding standards.

Q2. What are the tools required to unit test your code?
Ans. To test units or classes, we can use the “uniJest” python
standard library. It is the easiest way to test code, and the features
required are similar to the other unit tes4ng tools like TestNG, JUnit.

Q3. How to get indices of N maximum values in a NumPy array?


Ans. With the help of below code, we can get the maximum values in
a NumPy array :

Import numpy as nm

arr=nm.array([1, 6, 2, 4, 7])

print (arr.argsort() [-3:] [::-1])

Output:

[ 4 6 1]

Q4. How can you use ternary operators (Ternary) in Python?


Ans. Ternary operators are used to display condi4onal statements.
This consists of the true or false values. Syntax :

The ternary operator is indicated as:

Page 2 of 7
iNeuron Intelligence Pvt Ltd

[on_true] if [expression] else [on_false] x, y = 25, 50big = x if x <y else


y

Example: The expression is evaluated as if x <and else and, in this


case, if x <y is true, then the value is returned as big = x and if it is
incorrect then big = y will be returned as a result.

Q5. What does this mean? * args, ** kwargs? Why would we use it?
Ans. * Args is used when you are not sure how many arguments to
pass to a func4on, or if you want to pass a list or tuple of stored
arguments to a func4on.

** kwargs is used when we don’t know how many keyword


arguments to pass to a func4on, or it is used to pass the values from
a dic4onary as the keyword argument.

The args and kwargs iden4fiers are a conven4on, you can also use *
bob and ** billy but that would not be wise

Q6. Does Python have OOps concepts?


Ans. Python is an object-oriented programming language. This means
that any program can be solved in Python, crea4ng an object model.
However, Python can also be treated as a procedural and structural
language.

Q7. How do I save an image locally using Python whose URL I already
know?
Ans. We will use the following code to store an image locally from a
URL

Page 3 of 7
iNeuron Intelligence Pvt Ltd

import urllib.request

urllib.request.urlretrieve (“URL”, “file-name.jpg”)

Q8. How are percentages calculated with Python / NumPy?


Ans. Percentages can be calculated using the following code:

import numpy as np

a = np.array ([1,2,3,4,5])

p = np.percen4le (a, 50) #Returns 50%.

print (p)

Q9. When does Abnormal Termina4on occur?


Ans. First of all, I should men4on that abend or abnormal termina4on
is bad. You don’t want it to happen during your programming
experience. However, it is prac4cally unavoidable, in one way or
another especially when you are a beginner.

Abend is an error in your program during its execu4on, while the


main tasks con4nue to perform processes. This is caused by a code
error or some sooware problem.

Q10. Explain the bytes() func4on in Python.


Ans. The bytes() func4on in Python returns a bytes object. It converts
objects into bytes objects. It also creates empty bytes objects of the
specified size.

Page 4 of 7
iNeuron Intelligence Pvt Ltd

Q11. Explain the ‘with statement’.


Ans. In Python, the ‘with statement’ is used for excep4on handling
and resource management. It makes the code cleaner and readable
as it allows a file to be opened and closed while execu4ng a block of
code containing the ‘with statement’.

Q12. What are Pandas Data Frames?


Ans. Pandas DataFrame is a two-dimensional tabular data structure
with labelled axes. The data is aligned in a tabular manner in rows
and columns. Data Frames are widely used in data science, machine
learning, scien4fic compu4ng, etc.

Here are some features of Dataframes:

2-dimensional
Labelled axes (rows and columns)
Size-mutable
Arithme4c opera4ons can be performed on rows and columns.

Q13. How to combine Data Frames in Pandas?


Ans. We can combine Data Frames using the following func4ons:

Concat() func4on: It is used for ver4cal stacking.


pd.concat([data_frame1, data_frame2])

append(): It is used for horizontal stacking of DataFrames.


data_frame1.append(data_frame2)

join(): It is used to extract data from different DataFrames which have


one or more columns common.

Page 5 of 7
iNeuron Intelligence Pvt Ltd

Q14. How to access the top n rows of a dataframe?


Ans. To access the top n rows of a data frame, we will use df.head(n).

Q15. How to access the last n rows of a dataframe?


Ans. We will use df.tail(n) to access the last n rows of a dataframe.

Q16. What are Python namespaces?


Ans. A namespace is a mapping from names to objects. It is a system
that ensures that all the object names in a program are unique and
can be used without any conflict. Python maintains a namespace in
the form of a Python dic4onary. These namespaces are implemented
as dic4onaries with ‘name as key’ mapped to its respec4ve ‘object as
value’. Namespaces have different life4mes as they are ooen created
at different points in 4me.

Some of the namespaces in a Python program are:

Local Namespace – it contains local names inside a func4on. The


local namespace is created for a func4on call and lasts un4l the
func4on returns.
Global Namespace – It consists of the names from various imported
modules that are being used in the ongoing project. This namespace
is created when the package is imported into the script and lasts un4l
the script ends.
Built-In Namespace – This namespace contains built-in func4ons and
built-in excep4on names.

Q17. Write a python program to check if the number given is a


palindrome or not

Page 6 of 7
iNeuron Intelligence Pvt Ltd

Ans. Below is the code to check if the given number is palindrome or


not:
Num =input(“Enter a number:”)
if num==num[::-1]
print (“It is a Palindrome!”)
else:
print(“It is not a Palindrome!”)

Q18. What is Scope Resolu4on in Python?


Ans: In some cases, objects within the same scope have the same
name. However, they work differently. In such cases, scope resolu4on
help in Python automa4cally.

Q19. How is data abstrac4on done in Python?


Ans. It can be achieved in Python using abstract classes and
interfaces. Data abstrac4on only supplies the necessary details and
hides the implementa4on.
Abstrac4on is selec4ng data from a larger pool to show only the
relevant details to the object.

Page 7 of 7
iNeuron Intelligence Pvt Ltd

Q1. Which of the following defini3ons 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 defini3ons and statements
Answer. b. A folder of python modules is called as package of
modules.

Q2. What is the order in which namespaces in Python looks for an


iden3fier?
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
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.

Q3. 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.

Page 2 of 14
iNeuron Intelligence Pvt Ltd

Q4. Which of the following is the use of func3on in python?


1. Func3ons do not provide beKer 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.

Q5. Which of the following is a feature of Python Doc String?


1. All func3ons should have a docstring in python
2. Doc Strings can be accessed by the _doc_ aKribute on objects
3. This feature provides a very convenient way of associa3ng
documenta3on with python modules, func3ons, classes and
methods
4. All of the above
Answer. d. Python has a niSy feature, which is referred to as the
documenta3on 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 beKer along with making it easier to
understand.

Q6. Which of the following is the use of the func3on id() in python?
1. Every object does not have a unique id in Python
2. The id func3on in python returns the iden3ty of the object
3. None
4. All

Page 3 of 14
iNeuron Intelligence Pvt Ltd

Answer. b. Every func3on in Python has a unique id. The id() func3on
helps return the id of the object

Q7. What is the func3on of pickling in python?


1. Conversion of a python object
2. Conversion of database into list
3. Conversion of byte stream into python object hierarchy
4. Conversion of list into database
Answer. a. The process of pickling refers to sterilizing a Python object,
which means conver3ng a byte stream into python object hierarchy.
The process which is the opposite of pickling is called unpickling.

Q8. What is Python code-compiled or interpreted?


1. The code is both compiled and interpreted
2. Neither compiled nor interpreted
3. Only compiled
4. 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.

Q9. What will be the output of the following Python function?

len(["hello",2, 4, 6])?

a) Error

b) 6

Page 4 of 14
iNeuron Intelligence Pvt Ltd

c) 4

d) 3

Answer: c

Explanation: The function len() returns the length of the number of


elements in the iterable. Therefore, the output of the function shown
above is 4.

Q10. What is the order of namespaces in which Python looks for an


identifier?

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

Answer: c

Explanation: Python first searches for the local, then the global and
finally the built-in namespace.

Page 5 of 14
iNeuron Intelligence Pvt Ltd

Q11. What will be the output of the following Python program?

def foo(x):

x[0] = ['def']

x[1] = ['abc']

return id(x)

q = ['abc', 'def']

print(id(q) == foo(q))

a) Error

b) None

c) False

d) True

Answer: d

Explana3on: The same object is modified in the func3on.

Page 6 of 14
iNeuron Intelligence Pvt Ltd

Q12. What will be the output of the following Python program?

z=set('abc')

z.add('san')

z.update(set(['p', 'q']))

a) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}

b) {‘abc’, ‘p’, ‘q’, ‘san’}

c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}

d) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san’}

Answer: c

Explana3on: The code shown first adds the element ‘san’ to the set z.
The set z is then updated and two more elements, namely, ‘p’ and ‘q’
are added to it. Hence the output is: {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}

Q13. What will be the output of the following Python code?

print("abc. DEF".capitalize())

Page 7 of 14
iNeuron Intelligence Pvt Ltd

a) Abc. def

b) abc. def

c) Abc. Def

d) ABC. DEF

Answer: a

Explana3on: The first leKer of the string is converted to uppercase


and the others are converted to lowercase.

Q14. What will be the value of ‘result’ in following Python program?

list1 = [1,2,3,4]

list2 = [2,4,5,6]

list3 = [2,6,7,8]

result = list()

result.extend(i for i in list1 if i not in (list2+list3) and i not in result)

result.extend(i for i in list2 if i not in (list1+list3) and i not in result)

result.extend(i for i in list3 if i not in (list1+list2) and i not in result)

a) [1, 3, 5, 7, 8]

Page 8 of 14
iNeuron Intelligence Pvt Ltd

b) [1, 7, 8]

c) [1, 2, 4, 7, 8]

d) error

Answer: a

Explana3on: Here, ‘result’ is a list which is extending three 3mes.


When first 3me ‘extend’ func3on is called for ‘result’, the inner code
generates a generator object, which is further used in ‘extend’
func3on.

Q15. What will be the output of the following Python code?

>>>list1 = [1, 3]

>>>list2 = list1

>>>list1[0] = 4

>>>print(list2)

a) [1, 4]

b) [1, 3, 4]

c) [4, 3]

d) [1, 3]
Page 9 of 14
iNeuron Intelligence Pvt Ltd

Answer: c

Explana3on: Lists should be copied by execu3ng [:] opera3on.

Q16. What will be the output of the following Python program?

i=0

while i < 5:

print(i)

i += 1

if i == 3:

break

else:

print(0)

a) error

b) 0 1 2 0

c) 0 1 2

d) none of the men3oned

Page 10 of 14
iNeuron Intelligence Pvt Ltd

Answer: c

Explana3on: The else part is not executed if control breaks out of the
loop.

Q17. What will be the output of the following Python code?

x = 'abcd'

for i in range(len(x)):

print(i)

a) error

b) 1 2 3 4

c) a b c d

d) 0 1 2 3

Answer: d

Explana3on: i takes values 0, 1, 2 and 3.

Page 11 of 14
iNeuron Intelligence Pvt Ltd

Q18. What will be the output of the following Python program?

def addItem(listParam):

listParam += [1]

mylist = [1, 2, 3, 4]

addItem(mylist)

print(len(mylist))

a) 5

b) 8

c) 2

d) 1

Answer: a

Explana3on: + will append the element to the list.

Q19.What will be the output of the following Python code snippet?

z=set('abc$de')

Page 12 of 14
iNeuron Intelligence Pvt Ltd

'a' in z

a) Error

b) True

c) False

d) No output

View Answer

Answer: b

Explana3on: The code shown above is used to check whether a


par3cular item is a part of a given set or not. Since ‘a’ is a part of the
set z, the output is true. Note that this code would result in an error in
the absence of the quotes.

Q20. What will be the output of the following Python expression?

round(4.576)

a) 4

b) 4.6

c) 5

d) 4.5
Page 13 of 14
iNeuron Intelligence Pvt Ltd

View Answer

Answer: c

Explana3on: This is a built-in func3on which rounds a number to give


precision in decimal digits. In the above case, since the number of
decimal places has not been specified, the decimal number is rounded
off to a whole number.

Page 14 of 14
iNeuron Intelligence Pvt Ltd

Q1. What will be the output of the following Python code?

x = [[0], [1]]

print((' '.join(list(map(str, x))),))

a) 01

b) [0] [1]

c) (’01’)

d) (‘[0] [1]’,)

Answer: d

ExplanaKon: (element,) is not the same as element. It is a tuple with


one item.

Q2. The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the


same.

a) True

b) False

View Answer

Answer: a

Page 2 of 12
iNeuron Intelligence Pvt Ltd

ExplanaKon: Although the presence of parenthesis does affect the


order of precedence, in the case shown above, it is not making a
difference. The result of both of these expressions is 1.333333333.
Hence the statement is true.

Q3. What will be the value of the following Python expression?

4+3%5

a) 4

b) 7

c) 2

d) 0

Answer: b

ExplanaKon: The order of precedence is: %, +. Hence the expression


above, on simplificaKon results in 4 + 3 = 7. Hence the result is 7.

Q4. What will be the output of the following Python code?

string = "my name is x"

for i in string:

print (i, end=", ")


Page 3 of 12
iNeuron Intelligence Pvt Ltd

a) m, y, , n, a, m, e, , i, s, , x,

b) m, y, , n, a, m, e, , i, s, , x

c) my, name, is, x,

d) error

Answer: a

ExplanaKon: Variable i takes the value of one character at a Kme.

Q5. What will be the output of the following Python code snippet?

a = [0, 1, 2, 3]

for a[0] in a:

print(a[0])

a) 0 1 2 3

b) 0 1 2 2

c) 3 3 3 3

d) error

Answer: a

Page 4 of 12
iNeuron Intelligence Pvt Ltd

ExplanaKon: The value of a[0] changes in each iteraKon. Since the


first value that it takes is itself, there is no visible error in the current
example.

Q6. What are the different subsets of SQL?

Ans-

• Data DefiniKon Language (DDL) – It allows you to perform various


operaKons on the database such as CREATE, ALTER, and DELETE
objects.
• Data ManipulaKon Language (DML) – It allows you to access
and manipulate data. It helps you to insert, update, delete and
retrieve data from the database.
• Data Control Language (DCL) – It allows you to control access to
the database. Example – Grant, Revoke access permissions.

Q7. What do you mean by DBMS? What are its different types?

Ans- A Database Management System (DBMS) is a sojware


applicaKon that interacts with the user, applicaKons, and the database
itself to capture and analyze data. A database is a structured collecKon
of data.

A DBMS allows a user to interact with the database. The data stored in
the database can be modified, retrieved and deleted and can be of any
type like strings, numbers, images, etc.

There are two types of DBMS:

• RelaKonal Database Management System: The data is stored in


relaKons (tables). Example – MySQL.

Page 5 of 12
iNeuron Intelligence Pvt Ltd

• Non-RelaKonal Database Management System: There is no


concept of relaKons, tuples and amributes. Example – MongoDB

Q8. What is a Self-Join?

Ans- A self-join is a type of join that can be used to connect two


tables. As a result, it is a unary relaKonship. Each row of the table is
amached to itself and all other rows of the same table in a self-join.
As a result, a self-join is mostly used to combine and compare rows
from the same database table.

Q9. What is the SELECT statement?

Ans- A SELECT command gets zero or more rows from one or more
database tables or views. The most frequent data manipulaKon
language (DML) command is SELECT in most applicaKons. SELECT
queries define a result set, but not how to calculate it, because SQL is
a declaraKve programming language.

Q10. What are some common clauses used with SELECT query in
SQL?

Ans- The following are some frequent SQL clauses used in


conjuncKon with a SELECT query:

WHERE clause: In SQL, the WHERE clause is used to filter records that
are required depending on certain criteria.
ORDER BY clause: The ORDER BY clause in SQL is used to sort data in

Page 6 of 12
iNeuron Intelligence Pvt Ltd

ascending (ASC) or descending (DESC) order depending on specified


field(s) (DESC).
GROUP BY clause: GROUP BY clause in SQL is used to group entries
with idenKcal data and may be used with aggregaKon methods to
obtain summarised database results.
HAVING clause in SQL is used to filter records in combinaKon with
the GROUP BY clause. It is different from WHERE, since the WHERE
clause cannot filter aggregated records.

Q11. What is UNION, MINUS and INTERSECT commands?

Ans- The UNION operator is used to combine the results of two


tables while also removing duplicate entries.

The MINUS operator is used to return rows from the first query but
not from the second query.

The INTERSECT operator is used to combine the results of both


queries into a single row.
Before running either of the above SQL statements, certain
requirements must be saKsfied –
Within the clause, each SELECT query must have the same amount of
columns.
The data types in the columns must also be comparable.
In each SELECT statement, the columns must be in the same order.

Page 7 of 12
iNeuron Intelligence Pvt Ltd

Q12. What is Cursor? How to use a Cursor?

Ans- Ajer any variable declaraKon, DECLARE a cursor. A SELECT


Statement must always be coupled with the cursor definiKon.

To start the result set, move the cursor over it. Before obtaining rows
from the result set, the OPEN statement must be executed.

To retrieve and go to the next row in the result set, use the FETCH
command.

To disable the cursor, use the CLOSE command.

Finally, use the DEALLOCATE command to remove the cursor


definiKon and free up the resources connected with it.

Q13. List the different types of relaKonships in SQL.

Ans- There are different types of relaKons in the database:

One-to-One – This is a connecKon between two tables in which each


record in one table corresponds to the maximum of one record in the
other.

One-to-Many and Many-to-One – This is the most frequent


connecKon, in which a record in one table is linked to several records
in another.

Many-to-Many – This is used when defining a relaKonship that


requires several instances on each sides.

Self-Referencing RelaAonships – When a table has to declare a


connecKon with itself, this is the method to employ.
Page 8 of 12
iNeuron Intelligence Pvt Ltd

Q14. What is OLTP?

Ans- OLTP, or online transacKonal processing, allows huge groups of


people to execute massive amounts of database transacKons in real
Kme, usually via the internet. A database transacKon occurs when
data in a database is changed, inserted, deleted, or queried.

Q15. What are the differences between OLTP and OLAP?

Ans- OLTP stands for online transacKon processing, whereas OLAP


stands for online analyKcal processing. OLTP is an online database
modificaKon system, whereas OLAP is an online database query
response system.

Q16. How to create empty tables with the same structure as another
table?

Ans- To create empty tables:


Using the INTO operator to fetch the records of one table into a new
table while seung a WHERE clause to false for all entries, it is
possible to create empty tables with the same structure. As a result,
SQL creates a new table with a duplicate structure to accept the
fetched entries, but nothing is stored into the new table since the
WHERE clause is acKve.

Page 9 of 12
iNeuron Intelligence Pvt Ltd

Q17. What is PostgreSQL?

Ans- In 1986, a team lead by Computer Science Professor Michael


Stonebraker created PostgreSQL under the name Postgres. It was
created to aid developers in the development of enterprise-level
applicaKons by ensuring data integrity and fault tolerance in systems.
PostgreSQL is an enterprise-level, versaKle, resilient, open-source,
object-relaKonal database management system that supports
variable workloads and concurrent users.

Q18. What are SQL comments?

Ans- SQL Comments are used to clarify porKons of SQL statements


and to prevent SQL statements from being executed. Comments are
quite important in many programming languages. The comments are
not supported by a Microsoj Access database. As a result, the
Microsoj Access database is used in the examples in Mozilla Firefox
and Microsoj Edge.
Single Line Comments: It starts with two consecuKve hyphens (–).
MulK-line Comments: It starts with /* and ends with */.

Q19. What is the usage of the NVL () funcKon?

Ans- You may use the NVL funcKon to replace null values with a
default value. The funcKon returns the value of the second
parameter if the first parameter is null. If the first parameter is
anything other than null, it is lej alone.

Page 10 of 12
iNeuron Intelligence Pvt Ltd

This funcKon is used in Oracle, not in SQL and MySQL. Instead of


NVL() funcKon, MySQL have IFNULL() and SQL Server have ISNULL()
funcKon.

Q20. Explain character-manipulaKon funcKons? Explains its different


types in SQL.

Ans- Change, extract, and edit the character string using character
manipulaKon rouKnes. The funcKon will do its acKon on the input
strings and return the result when one or more characters and words
are supplied into it.

The character manipulaKon funcKons in SQL are as follows:

A) CONCAT (joining two or more values): This funcKon is used to join


two or more values together. The second string is always appended
to the end of the first string.

B) SUBSTR: This funcKon returns a segment of a string from a given


start point to a given endpoint.

C) LENGTH: This funcKon returns the length of the string in numerical


form, including blank spaces.

D) INSTR: This funcKon calculates the precise numeric locaKon of a


character or word in a string.

E) LPAD: For right-jusKfied values, it returns the padding of the lej-


side character value.

F) RPAD: For a lej-jusKfied value, it returns the padding of the right-


side character value.

Page 11 of 12
iNeuron Intelligence Pvt Ltd

G) TRIM: This funcKon removes all defined characters from the


beginning, end, or both ends of a string. It also reduced the amount
of wasted space.

H) REPLACE: This funcKon replaces all instances of a word or a


secKon of a string (substring) with the other string value specified.

Page 12 of 12
iNeuron Intelligence Pvt Ltd

Q1. What is the type of programming language supported by


Python?
1. Object-oriented
2. Functional programming
3. Structured programming
4. All of the above

Answer. d. Python is an interpreted programming language,


supporting object-oriented, structured, and functional programming.

Q2. When Python is dealing with identifiers, is it case sensitive?


1. Yes
2. No
3. Machine dependent
4. Can’t say
Answer. a. It is case sensitive.
Q72. 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 written
in any text editor. We need to use the extension .py to save these
files.

Q3. All the keywords in Python are in_


1. Lower case
2. Upper case
3. Capitalized

Page 2 of 8
iNeuron Intelligence Pvt Ltd

4. None of the above


Answer. d. Only True, False and None are capitalized and all the
others in lower case.

Q4. What does pip mean in Python?


1. Unlimited length
2. All private members must have leading and trailing underscores
3. Preferred Installer Program
4. None of the above
Answer. c. Variable names can be of any length.

Q5. The built-in function in Python is:


1. Print ()
2. Seed ()
3. Sqrt ()
4. Factorial ()
Answer. a. The function seed is a function which is present in the
random module. The functions sqrt and factorial are a part of the
math module. The print function is a built-in function which prints a
value directly to the system output.

Q6. Which of the following definitions 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 definitions and statements

Page 3 of 8
iNeuron Intelligence Pvt Ltd

Answer. b. A folder of python modules is called as package of


modules.

Q7. What is the order in which namespaces in Python looks for an


identifier?
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
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.

Q8. 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.

Q9. Which of the following is the use of function in python?


1. Functions do not provide better modularity for applications
2. One can’t create our own functions
3. Functions are reusable pieces of programs

Page 4 of 8
iNeuron Intelligence Pvt Ltd

4. All of the above


Answer. c. Functions are reusable pieces of programs, which allow us
to give a name to a particular block of statements, allowing us to run
the block using the specified name anywhere in our program and any
number of times.

Q10. Which of the following is a feature of Python Doc String?


1. All functions should have a docstring in python
2. Doc Strings 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.

Q11. Which of the following is the use of the function id() in python?
1. Every object does not have a unique id in Python
2. The id function in python returns the identity of the object
3. None
4. All
Answer. b. Every function in Python has a unique id. The id() function
helps return the id of the object

Page 5 of 8
iNeuron Intelligence Pvt Ltd

Q12. What is the function of pickling in python?


1. Conversion of a python object
2. Conversion of database into list
3. Conversion of byte stream into python object hierarchy
4. Conversion of list into database
Answer. a. The process of pickling refers to sterilizing a Python object,
which means converting a byte stream into python object hierarchy.
The process which is the opposite of pickling is called unpickling.

Q13. What is Python code-compiled or interpreted?


1. The code is both compiled and interpreted
2. Neither compiled nor interpreted
3. Only compiled
4. 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.

Q14. The abs function returns the


a) The absolute value of the specific number
b) The average value of some numbers
c) Mean value for the list of numbers
d)None of the above

Answer
a) The absolute value of a specified number

Page 6 of 8
iNeuron Intelligence Pvt Ltd

Q15. The output of bool(‘’) will return


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

Answer
a)True

Q16. For the given program


def mul(x):
print(3*x)
if we call the function like mul(“ Hello”) the output should be

a) Hello^3
b) Hello Hello Hello
c) Error
d) None of the above

Answer
Hello Hello Hello

Q17. Parameters of a function can be defined


a) During the function creation
b) During the function calling
c)To find the bug in a function
d)None of the above

Answer
a) During function creation

Page 7 of 8
iNeuron Intelligence Pvt Ltd

Q18. What is MySQL?


MySQL is a Relational Database Management System (RDMS) such as
SQL Server, Informix, etc., and uses SQL as the standard database
language. It is open-source software backed by Oracle and used to
deploy cloud-native applications using an opensource database.

Q19. What is a Database?


It is the structured form of data stored in a well-organized manner
that can be accessed and manipulated in different ways. The
database is based on the collection of schemas, tables, queries, and
views. In order to interact with the database, different database
management systems are used. MySQL is used in WordPress and
gives you the option to create a MySQL database and its User with
the help of a control panel (cPanel).

Q20. Can you explain tables and fields?


The table is the set of organized data stored in columns and rows.
Each database table has a specified number of columns known as
fields and several rows which are called records. For example:

Table: Student

Field: Std ID, Std Name, Date of Birth

Data: 23012, William, 10/11/1989

Page 8 of 8

You might also like