CAPGEMINI – Python Interview Questions
Here is the list of Python Interview Questions which are recently asked in Capgemini company. These questions are included for both Freshers and Experienced professionals. Our Python Training has Answered all the below Questions.
1. Define iterators in Python?
An iterator is an object that contains a countable number of values. in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__() .
2. How does a function return values?
A return is a value that a function returns to the calling script or function when it completes its task. Adding a description for the return, helps you and anyone else using your function to determine exactly what the value should be used for within the calling script or function.
3. What are the key features of Python?
- Easy to Use, Read ,Write
- Free and Open Source
- Object-Oriented and High Level Programming
- GUI Programming Support with Extensible features
- Portable and Integrated language
4. What is the difference between list and tuple in Python?
The most important differences between list and tuple is that list is mutable, whereas a tuple is immutable. This means that lists can be changed, and tuples cannot be changed.
5. Define slicing in Python?
The slice() function returns a slice object. A slice object is used to specify how to slice a sequence. You can specify where to start the slicing, and where to end. You can also specify the step, which allows you to e.g. slice only every other item.
6. What are the two major loop statements?
The group of statements being executed repeatedly is called a loop. There are two loop statements in Python: for and while.
7. How can Python be an interpreted language?
Python is called an interpreted language because it goes through an interpreter, which turns code you write into the language understood by your computer's processor.
8. What happens when a function doesn’t have a return statement? Is this valid?
A function without an explicit return statement returns None . In the case of no arguments and no return value, the definition is very simple. Calling the function is performed by using the call operator () after the name of the function.
9. Define package in Python?
Packages are namespaces which contain multiple packages and modules themselves. They are simply directories, but with a twist. Each package in Python is a directory which MUST contain a special file called __init__.py .
10. How can we make a Python script executable on Unix?On UNIX systems, Python scripts can be made executable using the following process:
- Add this line as the first line in the script: #!/usr/bin/env python3.
- At the UNIX command prompt, type the following to make myscript.py executable.
- Move myscript.py into your bin directory, and it will be runnable from anywhere.
11. Which command is used to delete files in Python?
os. rmdir() method in Python is used to remove or delete a empty directory. OSError will be raised if the specified path is not an empty directory
12. Define pickling and unpickling in Python?
“Pickling” is the process whereby a Python object hierarchy is converted into a byte stream and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy.
13. What is a boolean in Python?
The python data type bool is used to store two values i.e. True and False. Bool is used to test whether the result of an expression is true or false.
14. What is Python String format and Python String replace?
Python String format() is a function used to replace, substitute, or convert the string with placeholders with valid values in the final string. It is a built-in function of the Python string class, which returns the formatted string as an output.
15. What are the functions in Python?
A function is a block of organized, reusable code that is used to perform a single, related action. Python gives you many built-in functions like print(), etc. but you can also create your own functions.
16. Define the term lambda?
The lambda keyword is used to define an anonymous function in Python. It has the following syntax: Syntax: lambda arguments: expression. This function can have any number of arguments but only one expression, which is evaluated and returned.
17. Define self in Python?
In Python, the word self is the first parameter of methods that represents the instance of the class. Therefore, in order to call attributes and methods of a class, the programmer needs to use self.
18. What happens when a function doesn’t have a return statement? Is this valid?
19. How can we make a Python script executable on Unix?
20. How do we convert the string to lowercase?
In Python, lower() is a built-in method used for string handling. The lower() methods returns the lowercased string from the given string. It converts all uppercase characters to lowercase. If no uppercase characters exist, it returns the original string
21. How can we debug a Python program?Debugging in Python
- The interface looks similar to that of the interactive shell that Python provides. We can test out the values passed into the function by typing them out: T
- To step to the next line, we use the key n , which means next , to step down the code line by line.
22. Write Python code to check the given sequence is a palindrome or not?
number=int(input("Enter any number :")) #store a copy of this number temp=number #calculate reverse of this number reverse_num=0 while(number>0): #extract last digit of this number digit=number%10 #append this digit in reveresed number reverse_num=reverse_num*10+digit #floor divide the number leave out the last digit from number number=number//10 #compare reverse to original number if(temp==reverse_num): print("The number is palindrome!") else: print("Not a palindrome!")
TOP MNC's PYTHON INTERVIEW QUESTIONS & ANSWERS
Here we listed all Python Interview Questions and Answers which are asked in Top MNCs. Periodically we update this page with recently asked Questions, please do visit our page often and be updated in Python.
To become a Python Certified professional and join in your dream company, Enroll now for our Best Python Training. We help you to crack any level of Python Interviews and We offering Python Training with 100% Placements.