Python Interview Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

INTERVIW QUESTIONS

DAY:1
1.what is python?
Python is an interpreted, object oriented, high-level programming
language with dynamic semantics. It is a High –level programming
language.

2.What kind of applications we can develop using python?


Python is a high level general purpose scripting language which is
used for develop the following applications:
➢ Stand Alone Application
➢ Web Application
➢ Enterprise Application
➢ Test Automation
➢ Networking
➢ IOT (Internet of Things)
➢ Artificial Intelligence
➢ Data Science

3.What are the advantages of python?


Python is a high level programming language.
• Easy to Read, Learn and Write
• Improved productivity
• Dynamically typed
• Free and Open-source
• Vat Libraries Support
• Portability
• Slow speed

4.Is python dynamic typed type language or not?


Python is both a Strongly typed and a dynamically typed language.
It also takes cares of the memory management.

5.Find difference between Static typing and Dynamic typing?

Dynamic typing Static typing


1. If the type of the variable 1. If the type of the variable is
Is checked at the runtime of the checked at the compile-time
code than the language is called of the code than the
a dynamically typed language. language is called static
typing.
2.Code will get interpreted/ 2. Code will not be compiled/
Compiled even if it contains interpreted until all the
errors
Error. are corrected.
3. Ex: python, Java script etc.. 3. Ex: Java, C, C++ ,etc..

6. What are the building data types of Python?


Python has 6 standard data types
1. Numbers--(includes Integer, Float, Complex)
2. String – It is an ordered sequence of characters.
3. List --It is used to store the group of elements under the
single name.
4. Dictionary—Dictionaries are used to store a huge amount
Of data.
5. Tuple --A tuple is a sequence of python objects separated
by commas. Tuples once created cannot be modified
6. Set -- set is defined by values separated by a comma inside
Braces {}.
7.What is meant by type casting and its types?
Type Casting: It is a method used to change the variables/ values
declared in a certain data type into a different data type.
In this we have two types of conversions:
1. Implicit Type Conversion: To convert lower data type into
higher data type, system will use implicit type conversion.
2. Explicit type conversion: To convert high data type into lower
data type programmer will use explicit type conversion.

8.How you can take data from keyboard in python?


We can take data by using the input () function to get python user
input from keyboard.
The input function gets user input and stores it into variable name.

9.What are the difference between input function and raw –input
function in python?

Input () function raw _ input () function


1.The python input function 1. The python raw _input
takes the value from the user. Function reads the input and
2.This function is called to tell returns as a string.
the program to stop and wait 2. It is used to get value from
for user to input values. The user.
3.It reads the input and returns 3. In the output the type of
the python type like int, list, tuple value stored is always string
etc… for raw _input ()

10. How you can convert given data into string type?
By using the str () function we can convert data into string function.
b=1.2
print(type(a)) #int
print(type(b)) #float.

11. How you can convert given string type data into integer type?
To convert a string to integer in python, use the int () function.
The initial string and the optional base to represent the data. Use the
syntax print(int(“STR”))
a=int (a)
print(type(a)) #int

12.How you can convert given integer type into float type?
By using float () function we can convert integers to floats. To use
this function we have to add integers Inside.
Ex: a=input (“enter the value for a:”)
Print(a)
a=float(a)
print(a)

13.How you can convert given data into complex number type?
By using complex () function we can convert data into complex type.
Take two separate numbers and convert them into complex.

Ex: a= 5+3j
print(type(a))
b= complex (10)
print(type(b))
print(b).
14.How we can store binary numbers in python?
In python we can use bin () function to convert or store binary values
in python. And the Int () function used as second argument.

15.How we can store octal numbers in python?


By using Oct () function to convert numbers to octal in python.
Syntax: a=11
#then in octal we write as
a=011

16.How we can store Hexadecimal number in python?


By using hex () function we can store hexadecimal number in python
NUM= int (input (“enter hexadecimal value:”)

17.How we can store true or false values in python?


These true or false value can be defined in Boolean type data. Used
to represent the truth value of an expression.
Ex: 1<=2 #true
0==1#false.

18. Shall we apply arithmetic operators on Boolean data?


Not all arithmetic operators are applicable on Boolean bur some are.
They are AND, OR, NOT operators. And also the && operator is used
to combine two Boolean value and it gives whether it’s true or false
results.

19.How we can store empty value in python?


By using keyword (none) empty value will be displayed.

20.Howwe can convert integer data type into binary data type?
By using bin () function we convert integer to binary data type in
python. And also format function.
EX: binary= bin (16)
Print(binary)

21.How we can convert given integer into octal type?


➢ Write the given integer number.
➢ If the given integer number given 8 in the octal number.
➢ If the number is greater than 7 then the divide the number
by 8.
➢ Note the remainder we get after division.

22. How we can convert given integer type into hexadecimal?


➢ Divide the decimal number by 16. Treat the division as an
integer division.
➢ Write down the remainder in hexadecimal.
➢ Divide the result again by 16. Treat the division as an integer
division.
➢ Repeat the process until result is 0.
➢ The hex value is the digit sequence of the remainders from the
past to first.

23. How you can convert given float number into binary type or not?
To convert a floating point decimal number into binary, first we
have to convert the integer part into binary form and then fractional
part into binary form and finally combine both results to get the final
answer.
1= (1)2
(1.0011…1)2
24.How you check the type of data the variable has in python?
To check the data type variable in python, use type () method. The
type () is a built-in method that returns the class type of the
argument object. And passed it as a parameter. You place the
variable inside a type () function, and python returns the data type.

25.What are the sequence data types on python?


There are three types of sequence data types
➢ List ()
➢ Tuple ()
➢ Range ()

26.What are the map data types in python?


We only use one type of map data that is dic ()

27.What are the callable data types in python?


The most typical “callable” are functions/methods such as def ():
and class objects such as class C, len, and C all are callable instances
that have a __call__ ().

28. How to create function in python?


To create the function in python we are going to use the keyword
called as “def”.
Syntax:
def function_ name (argumenta _list):
------------------
Function body
------------------

29. How to create empty function in python?


To create empty function in python we use syntax
Syntax:
Def fun ():
pass

30.What is the difference between if else and else if ladder?


If else: If else statement used to work with two.
And conditions are (if and else condition conditions).
Else if: Else if ladder is used to work with two or more conditions
And the conditions are (if and else if statements).

31. Write a example to demonstrate infinite loop in python?


EX: i=0
While i<=10:
Print (“hello world”) ======it prints 10 times.
INTERVIEW QUESTIONS
DAY-2
32.Write differences between list and tuple?
List: It is used to store the group of elements under the single name.
lists are mutable. Which means lists can be modified. List can be
empty.
Tuple: Tuples are immutable objects. Which means tuples cannot be
changed. And also tuples are more memory efficient than the list.
Tuple can be empty.

33.Is list is immutable or not?


List is mutable.

34.Is tuple is immutable or not?


Tuples are immutable.

35.How can we remove all elements from list?


By using clear () method we can able to remove all the present
elements from the list.

36.How can we remove all elements from tuple?


Tuples cannot be cleared directly. So for that, we have to convert a
tuple into list. After conversion by using clear () method we can
remove all the elements in it.

37.What is the difference between pop and remove method in list?


Pop method: pop method will always remove the end of the value in
the list.
Remove method: Remove method takes the value from the list.

38.How to remove list permanently from the memory?


Del id used to remove based on the given index in python.
39.How to find the length of the list?
By using Len () method we are able to find the length of the list.

40.How to add elements into tuple?


Tuple is immutable so it cannot modify any elements in it. So we
have to convert tuple into list. After that we can add element into
that list once it’s done again we have to convert list into tuple.

41.How we can convert tuple into list?


To convert a tuple into list in python use list () function. And list
returns a new list.
t1= (1,2,3,4,5)
l1=l1(t1)
print(type(l1))
print(l1)

42.How we can convert list into tuple?


To convert a list into tuple we use tuple () function. And it will return
tuple data type as output.

43.How to sort the list elements in descending order?


By using sort () function we can able to sort the elements of a list in
descending or ascending order using the default. And there is no
return value.
NUM= [1,2,3,4,5]
Num. sort (revers=true)
Print (“list in descending order:”)

44.How to find duplicate elements in list?


By adding elements /content of a list in a set. It’s because set
cannot display duplicate elements. Also we can compare the length
of the both list and set if both are equal then it means there are no
duplicate elements.

45.How to find maximum list element in the list?


By using max () and list. index () we can find maximum list element in
a list.
First we have to take two variables max=0 and i=0 then for this we
have to use while loop I > len (l1) after that we have to increment the
index value i =i+1 and print maximum value

46.How to find minimum list element in the list?

By using min () function and then use index () function.


First we have to take two variables min and i value and here we are
using while loop I > len (l1) and then min>l1(i)
And print minimum value of the list.

47.How to compare two lists equal or not?


We have to take two lists like l1 and l2.
By comparing two lists are equal if list 1 is equal to list2.
If they are equal print lists are equal
If they are not equal print lists are not equal.
Ex. l1= [1,2,3,4,5]
l2= [1,2,6,4,5]
if l1==l2:
print ("lists are equal:")
else:
print ("lists are not equal:")
48.How to create nested list in python?
First we have to take two lists they are l1 and l2.
And also take an empty list as l3.
Now, by using append () method we have to print l1 and l2 in l3 with
the help of append.
Now print the l3.
Ex: l1= [1,2,3]
l2= [4,5,6]
l3= []
l3. append(l1)
l3. append(l2)
print(l3)

49. Can we store a tuple in a list or not?


Yes, we can store a tuple in list.

50.How to iterate the list elements in python?


We can iterate the list elements in python by using various method
like for loop, while loop, and also loop and range.
First we have to create a list as l1
And then we have to find the length of the list len (list)
After that by using while loop we write i<length
Finally print the list

51.What list methods we cannot able to apply on tuple?


There are only two tuple methods count () and index () that a tuple
object can call.
And also it cannot assigned with append () and remove () methods
where, as list can be able to.
52.How many number of loops will taken by nested list?
Two loops will taken by nested list those are for loop and while loop.

53.Can we create nested tuple in python?


Tuples can be nested. And they are also contain lists, dictionaries
and other tuples. So, we can create a nested tuple in python.
Ex: t1= [1,2,3]
t2= [4,5,6]
t3= []
t3. append(t1)
t3. append(t2)
print(t3)

54.Can we store list as a element in tuple?


A tuple can contain a list as an element. Some tuples only contain
immutable objects such as strings.

55.How we can able to join two lists as a single list in python?


First we have to take two lists such as l1 and l2.
Later by using extend method writel1.extend(l2)
The print it is a concatenated list 1.
Ex: l1= [1,2,3,4,5]
l2= [6,7,8,9,10]
l1. extend(l2)
print(l1)

56.How we can store two tuples as a single tuple in python?


We can store two tuples as a single tuple by using + operator.
First we have to create two tuples such as t1 and t2.
Print tuple 1 and tuple 2
Later print two tuples as tuple 1+tuple2
Then print the result.
Ex: t1= [1,2,3,4,5]
t2= [6,7,8,9,10]
print(t1)
print(t2)
result=t1+t2
print(result)

57.Is python follows negative indexing or not?


Python supports negative indexing of arrays.

58.How we can print list elements using step wise?


By using index () method we can print list elements using step
wise.

59.How we can calculate number of nested list in a given list?


By using count method we will calculate the number of nested list
in a given list.

60.What is the difference between del, remove, pop, clear in python?


• Del method is nothing but it deletes the based on the index
elements
• Remove is nothing but it removes the value
• Pop is nothing but it removes the list from the end value
• Clear method is nothing but it removes total list
61.What is the difference between index and count in list?
Count: Count is about to count how many values in the given list.
Index: Index is used to find index () of given elements in the list .

DAY-3

62. How to convert list into set?


By using set () function we can convert a list into set. And also
when we convert the list into set all the duplicate values will be
removed.
63.How to convert tuple into set?
By using set () function we can convert a tuple into set. Set ()
function can take all iterables like list, tuple, string, dictionary and
converts them into set.

64.How to convert dictionary into set?


By using set () function we can convert a dictionary into a set.
Dictionary contains keys and values.

65.What is the difference between set and list?


Sets: A set is a collection which is unordered and unidexed, and
does not allow the duplicate values.
You cannot access items in a set by referring to an index.
Sets are mutable.
List: A list is a collection which is ordered and changeable.
In python lists are written with square brackets.
Lists are mutable.
You access the list items by referring to the index number.

66. What is the difference between dictionary and set?


Dictionary: A dictionary is unordered collection of data that
stores data in key-value pairs.
Set: A set is a collection which is unordered and unindexed , and
does not allow the duplicate values.

67.Whta is the difference between tuple and set?


Tuple: Tuple is a collection of values separated by commas.
Tuples are immutable.
We cannot modify the tuple once we create the elements .
Set: Set is an unordered collection of distinct immutable objects.
We cannot access the items in a set by referring to an index.

68.Can we apply indexing on set or not?


No we cannot apply indexing on sets.

69.How we can display all set elements in python?


A set is created by placing all the items (elements) inside curly
brackets {}, separated by comma or by using built-in set () function.
And also using for loop to create the set.
And pass each item as an argument to the add () function.

70.How to find the length of the set?


By using len function we can able to find the length of the set.
Ex: a={1,2,3,4,5}
Len (set)
Output is 5.

71.How to delete set permanently from the computer memory in


python?
By using the syntax of remove () method. we can able to delete the
set completely.
And also by using del () function we are able to do that. Sets are
unordered.

72.How to find the type of set in python?


We can find the type offset by using the
Syntax: types. setType =set
73.What is the type of empty set in python?
To make empty set type we use function set () without giving any
elements
74.List the methods of set in python?
There are some methods and those are
➢ Copy ()
➢ Add ()
➢ Discard ()
➢ Pop ()
➢ Remove ()
➢ Update ()
➢ Clear ()
75.How we can insert elements into the set?
By using add () method we can able to insert the elements into set.
76.What are the various ways to delete the element in the set?
There are some ways to delete the elements in the set.
Those are :
➢ Clear ()
➢ Remove ()
➢ Delete ()
➢ Pop ()
➢ Discard ()

77.What is the difference between set and frozen set?


SET :
➢ Set is used to store group of elements.
➢ Set can be empty.
➢ Set can not allows duplicate values.

Frozen set :
➢ Frozen set is a set which is used to make the set . and it is
not going to change again once we create the set.
➢ Frozen set cannot allow duplicate values.
➢ Frozen set can be empty.
78.How you can find two sets are disjoint or not?
We can find if two sets are disjoint or not by checking if they have
no common element in the set.
79.How to find the given set is super set to other set or not?
We can find the given set is super set or not by using the
Issuperset () method.
80.How to check the given set is subset to other set or not?
We can find the given set is subset or not by using the
Issubset () method.
81.What is the operator we used to check given set is super set or
not?
By using the assignment operator (=) we can able to check the given
set is super set or not.
82.What is the operator we used to check given set is subset or
not?
By using the assignment operator (=) we can able to check the given
set is sub set or not.
83.How to compare two sets are equal or not?
We can compare two sets are equal or not by using the if condition.
Ex : s1={1,2,3,4}
S2={5,6,7,8}
S3={5,6,7,8}
If (s2==s3):
Print (“two sets are equal”:)
84.What is the operator to compare two sets in python?
By using the assignment operator (==) we can able to compare two
sets in python.
85.How to find the difference between given two sets?
We can find the difference between given two sets by the following
two methods..
1. Operator (-)
2. Using difference () method
86.What is the symbol is used to find the difference of two sets?
By using the minus (-) symbol we can able to find the difference of
two sets.
87.What is the method is used to find the difference of two sets?
By using the difference () method returns the set of difference of
two sets.
88.How to find the union of two sets?
By using the union () method we can able to find the union of two
sets.
New _set= set
89.How to find the intersection of two sets?
We can find the intersection of two sets by two ways.
1. using & operator
2. Using intersection () method.

90.What is the difference between intersection and intersection


updata in python?
1. INTERSECTION : Intersection of two sets means common element
in both sets.
2.INTERSECTION UPDATE : Intersection update means both the two
sets of common elements is updated into the next set.
91.What is the function/ method used to find the given set is super
set or not?
➢ The method issuperset () returns true if the set has every
element of another set that is passed as a argument.
➢ If not, it returns false. Set X is said to be the superset of set Y if
all elements of Y are in X.

Day-4

92.What is the function / method used to find the given set is subset
or not?
➢ The function is used to subset.
➢ The issubset () method returns true if all elements of a set are
present in another set and it passed as an argument.

93.What is the function/or method is used to compare the given two


sets are disjoint or not?
➢ If we take two sets of different elements then we will aplly the
disjoint method then we will get the output is become “true”
➢ Otherwise we take same elements output get “false”.

94.What is the function/method is used to compare the given two


sets are same or not?
By using the equal () method (==) we can able to compare the given
two sets are same or not.

95.How to update the set elements in python?


By using the update () method we can able to update the set
elements in python.
96.How to find symmetric difference of given two numbers?
If difference of two sets , the result set is all unique elements which
is we will get removing the common elements.

97.How to find the symmetric difference update of two given sets?


By using the symmetric _ difference _ update () method we can able
to find the symmetric difference update of two numbers.

98.How to combine two sets in python?


By using the union () method in python we can able to combine two
sets in python.

99.How to delete the element in set without specifying the element


in python?
By using pop () method we can able to delete the elements in set
without specifying the elements in python.

100.Find the elements in S, which are not there in S2?


String rotation given two strings those are s1 and s2.
S2 is a rotation of another string s1.

102.How to find the maximum element in set?


By using the set inside the index method we can find the maximum
element in the set.

103.How to find the minimum element in set?


By using the set inside the index method we can find the minimum
Element in the list.

104.How to find the sum of the set elements?


➢ By using the while loop we can add the sum of the elements.
➢ After writing the loop we have to increase the sum value like
sum=sum+1
➢ After that we will get output sum of the elements.
105.How to find the average of set elements?
There is a way to find the average of a list of numbers in python.
Divide the sum () by len () method.

106.How to find the given element is there or not?


We can find the given element is there or not by using the in bulit
function count () method.
107.How to create a new set which is intersection of given two sets
and write the method name in python?
To create a new set which is intersection of given two sets by using
(assignment operator).
And there are method like (&,intersection () method ())
108.Create a new set which is disjoint of given two sets and write
the method?
To create a new set which is disjoint of given two sets by using the
(assignment operator).
And there are methods like(^,intersection _ difference method.

109.Create a set which is symmetric difference of given two sets and


write method?
To create a set which is difference of two sets by using the methods
(symmetric _difference () method)

110.Difference between discard and remove in python?


Discard Remove
1.Discard method is used to 1. Remove () method will work like
Delete to remove element discard () method remove to
From the list. Element from the set.
2 . method will directly 2. Remove () method also apply
for
apply for only () set method. Only set () method.

111.Difference between discard and pop in python?


Discard Pop
1.Discard method is used to delete 1. Pop () method is uses from
To remove element from the set. Set it deletes the element
From the start.
2.Discard () method will directly 2. Pop () method it uses from
Apply for only set () method. List deletes the elements
From the end.

112.Diffrence between remove and pop in case of set in python?


Remove Pop
1. Remove () method used to 1. Pop () method is used to
remove elements from the delete the element from the
Set. Start in set.

113.How to insert the new elements into the set?


By using add () method we can insert new elements from the set.

114.How to create dictionary in python?


We can create the dictionary in python by using the keys and pairs.
Syntax :
dictionary_name={key1:value1, key2:value2,….keyn:valuen}

115.What is difference between list and dictionary?


LIST DICTIONARY
1. List is used to store the 1.A dictionary is an unordered
group of elements under single collection used to store keys
name. and values.
2.list can allow duplicate values. 2.In dictionary values are always
Duplicate.
3.List can be empty. 3. In dictionary keys are always
Unique.

116.What is the difference between tuple and dictionary?


TUPLE DICTIONARY
1.Tuples are immutable. Once 1.A dictionary is an unordered
we create tuples it cannot be collection used to store keys
modified. Pairs.
2. Tuple can be empty. 2. In dictionary values will be
Duplicate.
3. Tuple can allows the 3. In dictionary keys are always
Duplicate values. unique.

117.What is the difference between set and dictionary?


SET DICTIONARY
1.A set is an unordered collection 1. A dictionary is an unorder
Used to store group of elements. collection used to store keys
and values.
2.Set cannot able to store dupli 2.In dictionary values are
Cate values. always duplicate.
3.In set we cannot able to apply. 3.In dictionary keys are
always unique.
118.Is dictionary follow indexing or not?
yes, it follows indexing .

119.In dictionary shall we have duplicate keys or not?


No, dictionary does not allow duplicate keys.

120.In dictionary shall we have duplicate value or not?


Yes, dictionary can allow duplicate values.
121.How many ways we have to create dictionary in python?
There are three major ways to create dictionary.
➢ One by selecting keys and values can create dictionary.
➢ One by using curly brackets.
➢ One by using tuples
➢ One by using strings also.

DAY-5

122. How to update dictionary?


By using the dict. Update () method to update a dictionary.

123.How to insert new keys into dictionary?


We can insert new keys into dictionary by using the method
Mydict[“newkey”] = ‘newValue”

124.How to compare two dictionaries are same or not?


We can compare two dictionaries are same or not by using if
condition.
125.What is mean by dictionary in python?
A dictionary consists of a collection of key-value pairs. Each key-
value pair maps the key to its associated value.

126.What are the various methods to add data into the dictionary?
For adding data into dictionary it cannot support add, append ,insert
methods.
So, to insert new elements in dictionary insert a new index key into
the dictionary. By this method we can add data into the dictionaries.

127.How to get only keys from dictionary?


We can get all the keys from a dictionary by using the dict. Keys ()
function.
It returns as an iterable that contains all the keys of a dictionary.

128.How to get only values from dictionary?


➢ We can get all values from dictionary by using the Values ()
method.
➢ The values method is a built in function in python that returns
object which represents a list of dictionaries that contain
values.

129.How to get both values and keys from dictionary?


➢ By using for loop to print all the keys and value pairs of a
dictionary.
➢ After that using the method of dict. Items to get both the
items.
➢ Finally print a pair during each iteration.

130.How to print dictionary data using loops?


You can loop through a dictionary by using for loop.
Print all key names in dictionary one by one.While using loops the
return values are the keys of the dictionary.
Syntax: for x in this dict:
Print(x)

131.What are the various methods we have to remove the data from
dictionary?
There two methods and those are pop () method and del () method.
Pop () method can be used to delete a key and a value associated
with it which means key-pair value from dictionary.

132.Shall we remove data using dictionary on dell keyboard?

133.How to find the given key is there in dictionary or not?


➢ By using the keys () method and IN operator we can define the
key is there or not in dictionary.
➢ Key method will return a list of keys available in the dictionary.
➢ If and in operators used to check the key is present or not.
➢ If it exists it will return as true if not it shows false.

134.How to find the given value is there in dictionary or not?


We can check the given value is there or not in dictionary by
Using the dic. value () method.
If the value is there it shows true or else it shows false.

135.What are the major difference between set and dictionary? Write
down the common methods and various methods of both?
Dictionaries and sets are identical. Except that set do not actually
contain values where as dictionary contains it also contains keys.

136.What are the various types we have to define the string?


There are three types that we can define a string in python.
They are :
➢ Single quotes
➢ Double quotes
➢ Triple quotes

137.How to compare two strings are equal or not?


We can compare two strings by using the Equality operator (==).
If the string is equal then we use this operator.
If its not equal use inequality operator (!=).

138.How to find the length of the string?


We can find the length of a string by using len () function in python.
There is another method that is:
By using for loop and create i=0 and when the loop ends the length
of the string will be stored in the I variable.

139.How to remove the spaces in string?


We can remove the spaces in string by using the strip () function and
also by using the trim () .function

140.How to convert given string into lower case characters/letters?


By using the string swapcase method () we can convert all uppercase
characters/leters into lower case characters.

141.How to convert given string into upper case characters/letters?


By using the string swapcase () metod we can convert all the lower
case characters /leters into uppercase characters.

142.How to find the given string is there or not in string?


We can find the given string is there or not in string by using the
In () operator.
It can easily check whether a string contains a substring or not in
python.
143.How to capitalize the string in python?
Create a string and then by using the upper () method on a string it
converts all the characters into uppercase.

144.Remove the given string in the string in all the places?


Take two strings s1 and s2 of length n and m respectively.
S1 can be reduced by removing all occurrences of the string s2 from
the string s1.
Ex:s1=”fffoxoxoxfxo”
S2=”fox”
Int N=s1.length():
Int M=s2.length():
Cout <<minlength (s1,N,s2,M)
Return=0

145.How to convert string into list?


By using split method we can convert string into list.
All the string elements will be split and stored in list.

146.How to convert string into set?


We can convert a string into set in python by using the syntax set
(iterable)
If there are no elements in the set it returns empty set.
If it contains elements in the set it deletes the duplicate sand returns
the set.
147.How to convert string into tuple?
We can convert a string into tuple by using five methods. Those are
Map () , tuple (), int (), split () functions will be used. The join ()
function also helpful to convert string into tuple.

148.How to convert string into dictionary?

149.How to copy given string into new string?


By using the in built function of (strcp) which means string copy
method used for header to copy one string file to other string file.

150.How to find the length of the string for the given range?
By using len () function we are able to find the length of the string
and for range we use (range(len)) function.

151.Shall we apply negative indexing on string or not?


Yes,we can apply negative indexing on string in python.

DAY-6
152.What is mean by class?
Class is building block of oops which is going to have both data and
as well as properties.

153.what is mean by object?


An object is simply a collection of data (variables) and
methods(functions) that act on those data.

154.Difference between class and object?


CLASS OBJECT
1. It is the primary concept of 1.An object is an instance of a
Object oriented programming. Class.
2.A class is a group of similar 2.It consists of properties to
Objects. Make particular data useful.
3.Class is a logical identity. 3.Objct is a physical entity.

155.How to create class in python?


To create class in python we are going to use a keyword called ‘class”
Syntax: class classname :
#data
_____
_____
_____
#method
______
______
______
156.How to create object in python?
To create object we use the class named “MyClass” to create objects.
157.A class can have how many objects?
A class contains n number of objects. Infinitely many.
158.What is mean by constructor?
Constructor is a method which is called automatically when we
create the object to the class.
159.What are the types of constructors?
In python we have two types of constructors.
They are: 1.Default constructor
2. Parameterized constructor
Default constructor: If a constructor does not have any arguments
then we can say the constructor is default constructor.
Parameterized construction: If a constructor having arguments or
parameters then we can say it is parameterized construction.

161.What is mean by parameterized constructor in python?


If a constructors having arguments or parameters then we can say it
as parameterized construction.

162.How to create constructor in python?


By using the method __init__() method we can create constructor.

163.A class can has both default and parameterized constructor or


not?
NO, it is not possible to create both default and parameterized
constructor in a class.

164.What is mean by inheritance?


INHERITANCE: It refers to giving one class properties to other class.
The class which is giving properties known as base/super/parent
class.
The class is which is taking properties known as derived/sub/child
class.

165.What are the types of inheritance?


There are two types of inheritance.
➢ Single inheritance
➢ Multilevel inheritance
166.What is mean by single inheritance?
SINGLE INHERITANCE: It single inheritance there are only two which
are parent and child class involved.
Which means it can enables a derived class to inherit attributes and
methods from a single parent class.

167.What is mean by multiple inheritance?


MULTIPLE INHERITANCE: It means multiple parent classes will give
properties to single child class.

168.What is mean by multilevel inheritance?


MULTILEVEL INHERITANCE: In this inheritance one class gives the
properties to another class, another class gives properties to some
other class, like=======a –b, b-c, c-d etc……

170.Expalin multiple inheritance with an example?


Python does not support multiple inheritance.

171.Explain multilevel inheritance with an example?


Ex:
Class A
#method
Def display (self):
Print(“this is class A”)
Class B(A)
#method
Def display 2 (elf):
Print(“this is class B)
Class C(B):
#method
def display 3(self):
Print(“this is classC”)
C2=c()
C2.display()
C2.display 1()
C2.display 2()

172.Explain differences between single and multiple inheritance?


SINGLE MULTIPLE
1.It is a type of inheritance 1.Multiple inheritance from when
That enables a derived class a class inherits from many base
to inherit attributes and methods classes.
from a single parent class.
2.A subclass inherits from a 2. A subclass inherits from
Single superclass. Multiple superclasses.

173. Explain differences between multiple and multilevel


inheritance?
MULTIPLE MULTILEVEL
1.Multiple inheritance is when 1.Multilevel inheritance is
A class inherits from many base when a class inherits from a
Classes. Derived class making that
2.The subclass inherits properties derived class a base class for
And methods from multiple super new class.
Classes. 2.Multilevel inheritance has 3
types.
174.What is mean by parent class, and write other names for it?
Parent class is a class being inherited from ,which is also called as
Base class.

175.What is mean by child class, and write other names for it?
Child class is a class that inherits from another class,also called as
derived class.

176.How we can call parent class constructor in child class?


By using (__) double underscore method we can call parent class
constructor in child class.

177.How we can call parent class method in child class?


If we want to call parent class method in child class we are going to
use “super method”

178.How we can call same class method in another method in same


class?
By using def f (self):
Ex:
Class A
#data
A=10
B=20
C=30
#method
Def.display (self)
Print(self.a)
Print(self.b)
Def.display2(self)
Self.display()
Print(self.c)

179.What is the use of self keyword in python?


It is used to access variables that belongs to the class.
The self parameter is a reference to the current instance of the class.

180.What is mean by instance variable in python?


Python class variables are declared within a class and their values are
the same across all instances of a class.
(Or)
Instance variable is a variable defined in class ,for which each
instantiated object of the class has separate copy or instace.

181.How you can call the method using self?


➢ First we have to create class A
➢ We have to enter the data we have
➢ Next in method we use self as (def display (self):

182.How to create empty method in python?


We can create empty method in python by using the pass statement.

DAY-7

183.How to create empty class in python?


In python we can create empty class by using the pass command .
It should create after the definition of the class object.

184.What is the use of “pass” keyword?


We can create empty methods in class with the help of a keyword
called “pass”.

185.What is mean by polymorphism?


POLYMORPHISM: Polymorphism means exhibiting multiple forms
based on scenario situations.

186.Types of polymorphism in python?


In python there are two types of polymorphism .
They are: 1. Static or compeltant polymorphism
2. Dynamic or runtime polymorphism.

187.What is means by method overloading n python?


Overloading is a method or operator that can do different
functionalities with the same name.

188.What is mean by method overriding in python?


It means when you have two methods with the same name that each
perform different tasks .It’s an important feature of inheritance.

189.Difference between method overloading and method overriding


in python?
Method overloading Method overriding
1.It means defining the same 1.In this both parent class and
Name with different number of child class will have same
Arguments or different type of method.and number of
Arguments. Arguments must be same.
2.To implement method over 2.Method overriding cannot be
Loading we do not require implemented without using
Inheritance. Inheritance.

190.What is the difference between constructor and method in


python?
CONSTRUCTOR METHOD
1.Constructor call automatically 1. Method will called by object in
When we create the object. Class.
2.Constructor will never return 2.Method will return a value.
Any value .
3.Constructor take arguments. 3. Method will also take
Arguments.

191.What is mean by data encapsulation?


DATA ENCAPSUATION: It means wrapping of both data as well as
methods into a single unit.
EX: class

192.What is mean by data abstraction?


➢ It is process by hiring the data what user does not require and
showing the data what user needs.
➢ We will implement data abstraction with the help of access
modifier and abstract classes.

193.Explain about public keyword in python?


➢ All members in a python class are public by default .
➢ Any member can be accessed from outside the class
environment.
➢ If the class member declared as public then it can be accessed
everywhere.
194.Explain about private keyboard in python?
➢ The private members of a class are only accessible within the
class.
➢ A private member can be defined by using a prefix (__) double
underscore.
➢ So in private modifiers case we cannot access the attribute.

195.Explain about protected keyboard in python?


➢ Python has a unique convention to make a member protected.
➢ That is adding prefix (_) single underscore.
➢ This prevents usage by outside entities unless it is a subclass.
➢ However, this does not fully perform the functionality of the
protected modifier.

196.What is the difference between public and private?


PUBLIC PRIVATE
1.Public can be accessed from 1. Private variables can only be
a ji
accessed inside the class.
Outside class.
2.If you make both data and 2.If you make data and methods
Methods as public then we can are private then we can access
Access the data and methods data only in the same class.
Anywhere in the program.
3.All members in a program 3.we use(__) double underscore
Are public by default. Before the data member .

197.What is the difference between public and protected?


PUBLIC PROTECTED
1.Public can be accessed from 1.Protected cannot be accessed
Outside class. From outside the class.
2.If you make both data and 2.If you make both data and
Methods as public then we can methods as protected then we
Access the data and methods can access the data methods
Anywhere in the python program. Only its child classes.
3.All members in a program 3.In protected we will give (_)
are public by default. Underscore before the member
of the class.

198.How to use private access specifier in python and explain with an


example?
To define data or method as private in python we will add (__)
double underscore at beginning of class member.
EX: class A:
#data
__a=10
#method
def __display(self):
print(“this is private method”)
def display (self):
print(self.__a)
self.__display()
a2=A()
a2.__display().
199.What is the difference between private and protected?
PRIVATE PROTECTED
1.Private variables can only be 1. Protected variables can be
Accessed inside the class. Accessed within the same
Package.
2.Private members are not 2.Protected member are inherited
Inherited in class. In class.
3.Data members of a class are 3.Data members of a class are
Declared private by adding a declared protected by adding a
Double underscore (__) before single underscore(_) before the
The data member. Data member.

200.How to use public access specifier in python and explain with an


example?
If you make both data and methods as public then we can access the
data and methods any where in the program (either child class or
outside class).
By default all embers off class are public.

201.How to use protected access specifier in python and explain with


an example?
To define data and methods as protected then give (_) underscore
symbol every member in the class using singe underscore (_) at
starting.
EX: class A
#data
_a=10
#method
def _display(self):
print(“this is protected”)
a2=A()
print(a2._a)
print(a2._display())

202.How to access parent class members in child classes?


Accessing parent class functions.
We have to call the constructor of parent class inside the constructor
of child class and then the object of a chid class can access the
methods of a child and attributes of the parent class.

203.What is mean by super method , in python?


SUPER METHOD: The super () function is used to give access to
methods and properties of a parent or sibling class.
204.What is mean by self and super method In python?
SELF METHOD: Self represents the instance of a class . By using the
“self” keyword we can access the attributes and methods of the class
in python.
SUPER METHOD: The super () function is used to give access to
methods and properties of a parent or sibling class.

205.What are the programming paradigms we have ?


The most popular programming paradigms are
1.Procedure oriented programming
2.Function oriented programming
3.Structure oriented programming
4.Object based programming
5.Object oriented programming

206.Explain about function oriented programming paradigm?


In this the complete the solution via.writing in the form of functions.
Function refers a group of statements.

207.Explain about procedure oriented programming paradigm?


➢ In this program we are going to write the solutions in the form
of procedures.
➢ Every procedure may contain a group of elements which
written in some language.
Ex: FROTRON

208.Explain about structure oriented programming paradigm?


In structured oriented programming the every line in the program is
returned based on a predefined structure which is given by the
lqnguage.

209.Explain about object based programming paradigm?


➢ In object based programming the complete solution we will get
because of the communication among objects.
➢ Object means which is used to store the data as well as
properties
Ex: Javascript.

210.Expalin about object oriented programming paradigm?


➢ In object oriented programming the complete programming or
the solution for the given problem is return in terms of classes
and objects.
➢ Objects are also used to provide communication between
classes and object of other classes.
➢ Object means instance of a class which is exist physically in real
world.
DAY-8
211.What is mean by identity operator in python?
Identity operators are used to compare the objects, not if they are
equal, but they are actually same object, with the same memory
location.

212.What is mean by membership operator?


Membership operators are operators used to validate the
membership of a value.
It test for membership in a sequence, such as strings, lists, or tuples.

213.What are the differences between identity and membership


operator?
MEMBERSHIP OPERATOR: Membership operators are operators
used to validate the membership of a value.
It tests for membership in a sequence such as lists, tuples, strings
IDENTY OPERATOR: In python identity operators are used to
determine whether a value is a certain class or type.
They are usually used to determine the type of data certain variable
content.

214.What are the differences between logical & and bitwise & in
python?
The major difference between them are
➢ The logical AND works on Boolean expressions, and returns
Boolean values only.
➢ The bitwise AND operator works on integer, short int, long,
unsigned int type data , and also returns that type of data .
215.What are the supported literals by python language?
➢ String literals
➢ Numeric literals
➢ Boolean literals
➢ Literal collections
➢ Special literals

216.What is mean by global variable?


Variables that are declared outside of a function are known as global
variables.

217.What is mean by local variable?


A variable declared inside the function’s body or in the local scopeis
known as a local variable.

218.What are the differences between global and local variable?


GLOBAL VARIABLE: A global variable is a variable that is accessible
globally.
LOCAL VARIABLE: A local variable is one that is only accessible to the
current scope.

219.Explain about global keyword in python?


In python, global keyword allows you to modify the variable outside
of the current scope.

220.What is the use of “def” keyword in python?


The def keyword is used to create , or define a function in python.

221.What is mean by positional arguments in python?


POSITIONAL ARGUMENTS: Positional arguments are arguments that
need to be included in the proper position or order.

222.What is mean by function in python?


In python, A function is a block of code which only run when it is
called.
A function can return data as a result.

223.What are the types of functions in python?


Built-in function : such as help () to ask for help, min () to get the
minimum value, print () to print an object to the terminal.
Anonymous functions: these are also called as lambda function
because they are not declared with the standard def keyword.

224.What is mean by return statement in python?


The python return statement is a special statement that you can use
inside a function or method to send the function’s result back to the
caller.
A return statement consists of the return keyword followed by an
optional return value.

225.What are the limitations of written statements in python?

226.What are the various types of functions supported by the


python?
➢ Python function with no argument and no return value.
➢ Function with no argument and with a return value.
➢ Function with argument and no return value.
➢ Function with argument and return value.

227.What is mean by default argument in python?


Default arguments in python functions are those arguments that
take default values if no explicit values are passed to these
arguments from the function call.

228.How to create function in python?


By using the function _ name () we can directly call the function.
229.How to create empty function in python?
In python, to write empty functions, we use pass statement.

230.What is mean by function overloading?


Function overloading is the ability to have multiple functions with
the same name but with different signatures/implementations.

231.What is the difference between function and method in python


1.Functions are not associated 1.Methods re associated with
With any object. The objects of the class they
Belong to.
2.We can invoke a function just 2. Methods represents the
By its name. behaviour of an object.

232.How to execute function in python?


Write the function name and then use the keyword to call the
function.

233.How many times I can call the function program in python?

234.What are the uses of function?


USES:
➢ It can reduce duplication of code.
➢ It can decompose complete problems into simpler pieces.
➢ It will also improve the clarity of code.
➢ Reuse of code
➢ It also do information hiding.

235.What is mean by anonymous function in python?


In python, anonymous function is defined without a name.

236.How to create anonymous functions in python?


Anonymous functions are defined using the lambda keyword.
So, they are called as lambda functions.

237.What is the use of Lambda keyword in python?


The lambda keyword is used to create small anonymous functions.

238.What are the differences between normal and anonymous


function in python?
NORMAL FUNCTIONS:
➢ Regular functions can have multiple expressions and
statements in their body.
➢ It is easy to interpret.
➢ To return an object from the function, return should be
explicity defined.
ANONYMOUS FUNCTION:
➢ Lambda functions can only have one expression in their
body.
➢ Interpretation might be tricky.
➢ No need of using the return statement.

239.What are the limitations of lambda keyword in python?


➢ Lambda functions can have 0 or 1 expression, not more.
➢ Single expression : they can contain either one expression or no
expression.
➢ We cannot put more than one expression in lambda function.

240.Can I use lambda keyword in normal function or not?


No ,we cannot use lambda keyword in normal function .

You might also like