Python Interview Questions
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?
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.
- Spark Certification & Training Material
- Python Interview Questions-1
- Python Interview Questions-2
- Python Interview Questions-3
- Python Interview Questions-4
- Python Interview Questions-5
- Python Interview Questions-6
- Python Interview Questions-7
- Python Interview Questions-8
- Python Interview Questions-9
- Python Interview Questions-10
- Cloudera (Hadoop/Data Engineer) Certification
- Hortonworks (BigData) Certifications
Home Spark Hadoop NiFi Java
1. Hortonworks® is a registered trademark of Hortonworks.
2. Cloudera® is a registered trademark of Cloudera Inc
3. Azure® is aregistered trademark of Microsoft Inc.
4. Oracle®, Java® are registered trademark of Oracle Inc
5. SAS® is a registered trademark of SAS Inc
6. IBM® is a registered trademark of IBM Inc
7. DataStax ® is a registered trademark of DataStax
8. MapR® is a registered trademark of MapR Inc.
2014-2017 © HadoopExam.com | Dont Copy , it's bad Karma |