Day1-Day25,29,30,33 Python Interview
Day1-Day25,29,30,33 Python Interview
Day1-Day25,29,30,33 Python Interview
Page | 2
iNeuron Intelligence Pvt Ltd
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
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.
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}
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.
Ans: C
Explanation: print(list1[1:8:2]) of the following will give output as
[23,2,9,75].
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?
print(min(list1))
A. c
B. C++
C. C
Ans: C
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. i only
B. i and ii only
C. iii and iv only
D. iv only
Ans- A
Page | 9
iNeuron Intelligence Pvt Ltd
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.
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.
Page 3 of 9
iNeuron Intelligence Pvt Ltd
Page 4 of 9
iNeuron Intelligence Pvt Ltd
Page 5 of 9
iNeuron Intelligence Pvt Ltd
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’>
Page 7 of 9
iNeuron Intelligence Pvt Ltd
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.
Page 9 of 9
iNeuron Intelligence Pvt Ltd
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.
Answer: b
Explana@on: eval can be used as a variable.
Page 3 of 8
iNeuron Intelligence Pvt Ltd
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.
Answer: d
Explana@on: Iden@fiers can be of any length.
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
Answer: d
Explana@on: Tuples are represented with round brackets.
Answer: b
Explana@on: Each object in Python has a unique id. The id() func@on
returns the object’s id.
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
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.
Answer: c
Explana@on: l (or L) stands for long.
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
Page 7 of 8
iNeuron Intelligence Pvt Ltd
Page 8 of 8
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
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.
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
Page 5 of 9
iNeuron Intelligence Pvt Ltd
Page 6 of 9
iNeuron Intelligence Pvt Ltd
a) list
b) dic\onary
c) array
d) tuple
Answer: a
Explana\on: List data type can store any values within it.
a) List_name[2:3]
b) List_name[-1]
c) List_name[0]
Page 7 of 9
iNeuron Intelligence Pvt Ltd
b) index
c) pop
d) Delete
Answer – c) pop
a) append
b) copy
c) reverse
d) sort
Answer- a) append
Page 8 of 9
iNeuron Intelligence Pvt Ltd
Page 9 of 9
iNeuron Intelligence Pvt Ltd
Page 2 of 8
iNeuron Intelligence Pvt Ltd
Answer: a
Explana>on: A frozen set is an immutable data type.
Page 3 of 8
iNeuron Intelligence Pvt Ltd
c) Can’t say
d) None of the men>oned
Answer: a
Explana>on: None.
Page 4 of 8
iNeuron Intelligence Pvt Ltd
Answer: a
Explana>on: None.
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
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.
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.
Page 6 of 8
iNeuron Intelligence Pvt Ltd
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
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 [].
Page 3 of 9
iNeuron Intelligence Pvt Ltd
Page 4 of 9
iNeuron Intelligence Pvt Ltd
Page 5 of 9
iNeuron Intelligence Pvt Ltd
Page 6 of 9
iNeuron Intelligence Pvt Ltd
Page 7 of 9
iNeuron Intelligence Pvt Ltd
Page 8 of 9
iNeuron Intelligence Pvt Ltd
Page 9 of 9
iNeuron Intelligence Pvt Ltd
Page 2 of 8
iNeuron Intelligence Pvt Ltd
The index of -1 refers to the last item, -2 to the second last item and
so on. For example,
Page 3 of 8
iNeuron Intelligence Pvt Ltd
c) 12_hello
d) None of these
Answer – c) 12_hello
Answer – b) True
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'
a) 0
b) 2
c) 1
d) 3
Answer – c) 1
Page 5 of 8
iNeuron Intelligence Pvt Ltd
Answer. d. Only True, False and None are capitalized and all the
others in lower case.
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.
Page 7 of 8
iNeuron Intelligence Pvt Ltd
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
Page 2 of 10
iNeuron Intelligence Pvt Ltd
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.
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.
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
num1=10
num2="20"
result=num1+int(num2)
print(result)
Ans- There are many collecRon data types which are supported by
Python-
Page 4 of 10
iNeuron Intelligence Pvt Ltd
Page 5 of 10
iNeuron Intelligence Pvt Ltd
c) complex Simplified
d) ASCII is used. Unicode is used.
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.
Page 7 of 10
iNeuron Intelligence Pvt Ltd
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.
Answer -Python has many inbuilt packages and modules. One of the
most useful modules is random. This module helps in generaRng
random numbers.
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
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.
Page 10 of 10
iNeuron Intelligence Pvt Ltd
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.
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
A. datatype ()
B. typeof()
C. type()
D. vartype()
View Answer
Ans: C
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.
A. []
B. {}
C. ()
D. set()
Ans: D
ExplanaJon: set() is used to create an empty set. So, OpJon D is
correct.
A. set
B. int
C. str
D. tuple
View Answer
Ans: A
Page 3 of 10
iNeuron Intelligence Pvt Ltd
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.
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.
Page 5 of 10
iNeuron Intelligence Pvt Ltd
Ans- B
ExplanaJon: Tuples are immutable while lists are mutable the correct
opJon with respect to Python.
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.
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).
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).
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.
Ans- C
ExplanaJon: 22
Page 8 of 10
iNeuron Intelligence Pvt Ltd
A. i only
B. i and ii only
C. iii and iv only
D. iv only
Ans- A
Page 10 of 10
iNeuron Intelligence Pvt Ltd
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.
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.
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
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.
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.
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
Ans: A
Explanation: If condition is true so pq will be the output. So, option A
is correct.
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.
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?
Ans: B
ExplanaDon: Else statement aaer loop will be executed only when
the loop condiDon becomes false. So, opDon B is correct.
A. TRUE
B. FALSE
C. Null
D. Both A and C
Page 6 of 11
iNeuron Intelligence Pvt Ltd
View Answer
Ans: B
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.
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.
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.
Ans: B
Page 8 of 11
iNeuron Intelligence Pvt Ltd
ExplanaDon: For statement always ended with colon (:). So, opDon B
is correct.
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?
Ans: B
Page 9 of 11
iNeuron Intelligence Pvt Ltd
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.
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
list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
sum = 0
Page 10 of 11
iNeuron Intelligence Pvt Ltd
sum1 = 0
if (elem % 2 == 0):
conDnue
if (elem % 3 == 0):
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
Page 2 of 11
iNeuron Intelligence Pvt Ltd
A. new
B. except
C. class
D. object
Ans: C
Page 3 of 11
iNeuron Intelligence Pvt Ltd
A. __init__
B. __init__()
C. init
D. init()
Ans: B
A. __init__()
B. self
C. both A and B
D. None of the above
Ans: B
A. delete
B. dedl
Page 4 of 11
iNeuron Intelligence Pvt Ltd
C. del
D. drop
Ans: C
A. Inheritance
B. Instance variable
C. FuncRon overloading
D. InstanRaRon
Ans: B
A. Class variable
B. Method
C. Operator overloading
D. Data member
Page 5 of 11
iNeuron Intelligence Pvt Ltd
Ans: D
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
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
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
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
A. acribute
B. object
C. argument
D. funcRon
Ans: D
Ans: B
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
Page 9 of 11
iNeuron Intelligence Pvt Ltd
Page 10 of 11
iNeuron Intelligence Pvt Ltd
Page 11 of 11
iNeuron Intelligence Pvt Ltd
print(a+b+c)
print(a+b*c+d)
print(a/b+c/d)
print(a+b*c+a/b+d)
Ans-
Page 2 of 9
iNeuron Intelligence Pvt Ltd
Equal
x=y
True if x is equal to y.
>
Greater than
x>y
<
Less than
x<y
>=
x >= y
<=
x <= y
!=
Not equal to
x != 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-
Page 4 of 9
iNeuron Intelligence Pvt Ltd
Answer. b. There are a lot of languages which have been implemented using
both compilers and interpreters, including C, Pascal, as well as python.
Answer. b. 16 October 2000. The idea of Python was conceived in the later
1980s, but it was released on a. 16 October 2000.
Answer. a. The new version of Python 3.0 was released on December 3, 2008.
Page 5 of 9
iNeuron Intelligence Pvt Ltd
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.
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.
Answer. d. Only True, False and None are capitalized and all the others in lower
case.
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
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
Answer. C. Python first searches for the local namespace, followed by the
global and finally the built-in namespace.
Page 9 of 9
iNeuron Intelligence Pvt Ltd
A. int
B. float
C. complex
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
A. Sequence Types
B. Binary Types
C. Boolean Types
D. None of the mentioned above
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.
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.
A. True
B. False
Answer: A) True
Explanation:
A. TRUE
B. FALSE
Answer: A) TRUE
Explanation:
A. Yes
B. No
Page 4 of 13
iNeuron Intelligence Pvt Ltd
Answer: A) Yes
Explanation:
A. Quotient
B. Divisor
C. Remainder
D. None of the mentioned above
Answer: C) Remainder
Explanation:
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
Explanation:
d={
<key>: <value>,
<key>: <value>,
Page 6 of 13
iNeuron Intelligence Pvt Ltd
<key>: <value>
Group
List
Dictionary
Answer: C) Dictionary
A. True
B. False
Answer: A) True
Explanation:
Page 7 of 13
iNeuron Intelligence Pvt Ltd
A. True
B. False
Answer: A) True
Explanation:
if condition:
if condition
if(condition)
Page 8 of 13
iNeuron Intelligence Pvt Ltd
Answer: A)
if condition:
A. if a<=100:
B. if (a >= 10)
C. if (a => 200)
D. None of the mentioned above
Answer: A) if a<=100:
Explanation:
Page 9 of 13
iNeuron Intelligence Pvt Ltd
A. if a<=100:
B. if (a >= 10)
C. if (a => 200)
D. None of the mentioned above
Answer: A) if a<=100:
Explanation:
Explanation:
Page 10 of 13
iNeuron Intelligence Pvt Ltd
Explanation:
a=7
if a>4: print("Greater")
Greater
Page 11 of 13
iNeuron Intelligence Pvt Ltd
Answer: A) Greater
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
x=13
else:
Both A and B
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?
if a <= 0:
b = b +1
else:
a=a+1
Both A and B
Explanation:
Page 3 of 17
iNeuron Intelligence Pvt Ltd
A. True
B. False
Answer: A) True
Explanation:
A. Alphabets
B. Numbers
C. Special symbols
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
A. load()
B. set() method
C. dump() method
D. None of the mentioned above
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.
A. set() method
B. dump() method
C. load() method
D. None of the mentioned above
Page 5 of 17
iNeuron Intelligence Pvt Ltd
Explanation:
7. The readline() is used to read the data line by line from the text
file.
A. True
B. False
Answer: A) True
Explanation:
Explanation:
Page 7 of 17
iNeuron Intelligence Pvt Ltd
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
A. if else if
B. if elif
C. if-else
D. None of the mentioned above
Answer: C) if-else
Explanation:
A. Jump
B. goto
C. compound
D. None of the mentioned above
Answer: B) goto
Page 10 of 17
iNeuron Intelligence Pvt Ltd
Explanation:
Page 11 of 17
iNeuron Intelligence Pvt Ltd
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
A. True
B. False
Answer: A) True
Explanation:
Page 12 of 17
iNeuron Intelligence Pvt Ltd
i=5
No output
Both A and B
Explanation:
Page 13 of 17
iNeuron Intelligence Pvt Ltd
a = 13
b = 15
A is greater
B is greater
Both A and B
Answer: B) B is greater
A. True
B. False
Answer: A) True
Explanation:
Page 14 of 17
iNeuron Intelligence Pvt Ltd
Explanation:
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:
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:
Page 17 of 17
iNeuron Intelligence Pvt Ltd
A. Initiate
B. Start
C. End
D. None of the mentioned above
Answer: C) End
Explanation:
2. Amongst which of the following is / are true about the while loop?
Explanation:
A. range()
B. set()
C. dictionary{}
D. None of the mentioned above
Answer: A) range()
Explanation:
for i in range(6):
print(i)
1
Page 3 of 14
iNeuron Intelligence Pvt Ltd
Answer: A)
Page 4 of 14
iNeuron Intelligence Pvt Ltd
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.
A. True
B. False
Answer: A) True
Explanation:
Page 5 of 14
iNeuron Intelligence Pvt Ltd
Explanation:
A. Write code
B. Specific task
Page 6 of 14
iNeuron Intelligence Pvt Ltd
Explanation:
def function_name(parameters):
...
Statements
...
...
Statements
Page 7 of 14
iNeuron Intelligence Pvt Ltd
...
...
Statements
...
Answer: A)
def function_name(parameters):
...
Statements
...
Explanation:
The range(6) is define as function. Loop will print the number from 0.
Page 8 of 14
iNeuron Intelligence Pvt Ltd
A. True
B. False
Answer: A) True
Explanation:
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
Explanation:
Call by value and Call by reference are the types of function calls in
Python.
def show(id,name):
Page 9 of 14
iNeuron Intelligence Pvt Ltd
show(12,"deepak")
13. Amongst which of the following is a function which does not have
any name?
Del function
Show function
Lambda function
A. Yes
Page 10 of 14
iNeuron Intelligence Pvt Ltd
B. No
Answer: A) Yes
Explanation:
A. True
B. False
Answer: A) True
Explanation:
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:
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?
Explanation:
Page 13 of 14
iNeuron Intelligence Pvt Ltd
Page 14 of 14
iNeuron Intelligence Pvt Ltd
Ans-
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.
Ans-
Page 3 of 11
iNeuron Intelligence Pvt Ltd
Ans-
Ans-
Page 4 of 11
iNeuron Intelligence Pvt Ltd
Ans-
Page 5 of 11
iNeuron Intelligence Pvt Ltd
Ans-
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
Page 7 of 11
iNeuron Intelligence Pvt Ltd
Page 8 of 11
iNeuron Intelligence Pvt Ltd
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-
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
Page 2 of 9
iNeuron Intelligence Pvt Ltd
b) Exponent
c) Mul.plica.on
d) Division
e) Addi.on
f) Subtrac.on
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
Page 3 of 9
iNeuron Intelligence Pvt Ltd
Page 4 of 9
iNeuron Intelligence Pvt Ltd
Ans-
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
Page 6 of 9
iNeuron Intelligence Pvt Ltd
Ans-
Page 7 of 9
iNeuron Intelligence Pvt Ltd
12
123
1234
Ans-
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.
Page 9 of 9
iNeuron Intelligence Pvt Ltd
Page 2 of 9
iNeuron Intelligence Pvt Ltd
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.
The amributes of a class are also called variables. There are three
access modifiers in Python for variables, namely
tup2 = (4,5,6)
Page 5 of 9
iNeuron Intelligence Pvt Ltd
Q12. How can you randomize the items of a list in place in Python?
Ans-
Page 6 of 9
iNeuron Intelligence Pvt Ltd
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.
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
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.
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
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’)
Page 9 of 9
iNeuron Intelligence Pvt Ltd
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:
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
Q5. What are nega8ve indexes and why are they used?
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 3 of 9
iNeuron Intelligence Pvt Ltd
Ans:
Page 4 of 9
iNeuron Intelligence Pvt Ltd
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.
Ans:
Page 6 of 9
iNeuron Intelligence Pvt Ltd
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’.
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:
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.
Q20. What are nega8ve indexes and why are they used?
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
Ans:
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.
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.
Ans:
Page 4 of 10
iNeuron Intelligence Pvt Ltd
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’.
Page 5 of 10
iNeuron Intelligence Pvt Ltd
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.
Page 6 of 10
iNeuron Intelligence Pvt Ltd
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.
To remove duplicate elements from the list we use the set() func;on.
unique_list = list(set(demo_list))
import os
os.remove("file_name.txt")
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
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
file_count("file.txt"))
Page 10 of 10
iNeuron Intelligence Pvt Ltd
• 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.
Q2. Whenever Python exits, why isn’t all the memory de-allocated?
Page 2 of 13
iNeuron Intelligence Pvt Ltd
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?
Page 3 of 13
iNeuron Intelligence Pvt Ltd
Nested Lists:
Numpy:
For example:
Page 5 of 13
iNeuron Intelligence Pvt Ltd
print(a(5, 6))
Page 7 of 13
iNeuron Intelligence Pvt Ltd
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
# monkeyy.py
class X:
def func(self):
Syntax:
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.
Page 10 of 13
iNeuron Intelligence Pvt Ltd
Page 11 of 13
iNeuron Intelligence Pvt Ltd
Ans-
Ans-
Page 12 of 13
iNeuron Intelligence Pvt Ltd
my_list.sort()
print (my_list)
Page 13 of 13
iNeuron Intelligence Pvt Ltd
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.
Page 3 of 5
iNeuron Intelligence Pvt Ltd
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.
Page 5 of 5
iNeuron Intelligence Pvt Ltd
Page 2 of 9
iNeuron Intelligence Pvt Ltd
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.
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:
Page 3 of 9
iNeuron Intelligence Pvt Ltd
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.
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.
Page 4 of 9
iNeuron Intelligence Pvt Ltd
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]]
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.
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.
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
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.
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]
Page 9 of 9
iNeuron Intelligence Pvt Ltd
Lists
Sets
Dic@onaries
Immutable built-in types:
Strings
Tuples
Numbers
os
sys
math
random
data @me
JSON
Page 2 of 8
iNeuron Intelligence Pvt Ltd
Page 3 of 8
iNeuron Intelligence Pvt Ltd
import array
import array as arr
from array import *
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.
Page 5 of 8
iNeuron Intelligence Pvt Ltd
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.
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.
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.
Page 8 of 8
iNeuron Intelligence Pvt Ltd
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.
Import numpy as nm
arr=nm.array([1, 6, 2, 4, 7])
Output:
[ 4 6 1]
Page 2 of 7
iNeuron Intelligence Pvt Ltd
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.
The args and kwargs iden4fiers are a conven4on, you can also use *
bob and ** billy but that would not be wise
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
import numpy as np
a = np.array ([1,2,3,4,5])
print (p)
Page 4 of 7
iNeuron Intelligence Pvt Ltd
2-dimensional
Labelled axes (rows and columns)
Size-mutable
Arithme4c opera4ons can be performed on rows and columns.
Page 5 of 7
iNeuron Intelligence Pvt Ltd
Page 6 of 7
iNeuron Intelligence Pvt Ltd
Page 7 of 7
iNeuron Intelligence Pvt Ltd
Page 2 of 14
iNeuron Intelligence Pvt Ltd
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
len(["hello",2, 4, 6])?
a) Error
b) 6
Page 4 of 14
iNeuron Intelligence Pvt Ltd
c) 4
d) 3
Answer: c
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
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
Page 6 of 14
iNeuron Intelligence Pvt Ltd
z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
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’}
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
list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
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
>>>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
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
Page 10 of 14
iNeuron Intelligence Pvt Ltd
Answer: c
Explana3on: The else part is not executed if control breaks out of the
loop.
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
Page 11 of 14
iNeuron Intelligence Pvt Ltd
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
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
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
Page 14 of 14
iNeuron Intelligence Pvt Ltd
x = [[0], [1]]
a) 01
b) [0] [1]
c) (’01’)
d) (‘[0] [1]’,)
Answer: d
a) True
b) False
View Answer
Answer: a
Page 2 of 12
iNeuron Intelligence Pvt Ltd
4+3%5
a) 4
b) 7
c) 2
d) 0
Answer: b
for i in string:
a) m, y, , n, a, m, e, , i, s, , x,
b) m, y, , n, a, m, e, , i, s, , x
d) error
Answer: a
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
Ans-
Q7. What do you mean by DBMS? What are its different types?
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.
Page 5 of 12
iNeuron Intelligence Pvt Ltd
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?
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
The MINUS operator is used to return rows from the first query but
not from the second query.
Page 7 of 12
iNeuron Intelligence Pvt Ltd
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.
Q16. How to create empty tables with the same structure as another
table?
Page 9 of 12
iNeuron Intelligence Pvt Ltd
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
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.
Page 11 of 12
iNeuron Intelligence Pvt Ltd
Page 12 of 12
iNeuron Intelligence Pvt Ltd
Page 2 of 8
iNeuron Intelligence Pvt Ltd
Page 3 of 8
iNeuron Intelligence Pvt Ltd
Page 4 of 8
iNeuron Intelligence Pvt Ltd
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
Answer
a) The absolute value of a specified number
Page 6 of 8
iNeuron Intelligence Pvt Ltd
Answer
a)True
a) Hello^3
b) Hello Hello Hello
c) Error
d) None of the above
Answer
Hello Hello Hello
Answer
a) During function creation
Page 7 of 8
iNeuron Intelligence Pvt Ltd
Table: Student
Page 8 of 8