Learn Python in Less than 8 Hrs Sitting @ Home /Desk with HandsOn


Q31. What all are logical operators in Python?

Ans: There are three logical operators in Python and, or and not. See example below

-          a>0 and a<10 # This condition is true only if a is greater than 0 and less than 10 . If a=100 than it will return false


-          a>0 or a<10 # this condition will return true, if either a is greater than 0 or less than 10 e.g. a=100 than also it will return true.


-          not (10 >100) # It will return true. Because first 10 >100, it means it is false but we are negating this condition. Hence, it will become true.


Q32. What is recursion?

Ans: A function calling itself. If you don’t have a base condition (to break the recursion). It can be infinite call which can lead your program to run indefinitely and then finally crash.


Q33. What do you mean by dead code?

Rounded Rectangle: Learn Python in less than 8 Hrs (Sitting @ Home/Desk)Ans: A part of the code, which is never executed is known as dead code. This is generally written after the return statement and will never be executed.


Q34. What is the length of empty string?

Ans: Length of empty string will always be 0 and it will be represented as ‘’.


Q35. What does it mean string is an immutable object?

Ans : String is considered an immutable object because. Once, you create it you cannot change its value.



a.replace(‘A’, ‘S’) # this will not work and give error.


Q36. What is the method?

Ans: Method is a function only, but it is associated with the object. And can be called using dot notation.



Q37. How do you represent file in Python?

Ans: A file is represented using file object. For instance you have a file “c:/hadoopexam.txt” . If you want to read or write in this file you have to use Python file object.


Q38. What is the list in Python?

Ans: In python list is a sequence of values e.g. [“Amit”,”Rakesh”,”Rohit”,”Umesh”] is a list and contains 4 elements. List is represented using [] bracket. And it’s indexing start with 0. So here value at index 0 is “Amit” and value at index 3 is “Umesh” and there is no value at index 4.


Q39. Can a list contain another list?

Ans: Yes, a list can contain another list as below


[“Amit”,”Rakesh”,”Rohit”,”Umesh” , [“Mumbai” , “Delhi” , “Banglore” ,”Chennai”]]


Q40. What is an accumulator?

Ans : Accumulator is a variable, which generally used in the loop to accumulate the values in each iteration. E.g. if you want to add all the values in a list [1,2,3,4] . Then, you will be creating an accumulator which will hold the sum till previous iteration.

 Learn Python in Less than 8 Hrs Sitting @ Home /Desk with HandsOn