TECH MAHINDRA – Python Interview Questions
Here is the list of Python Interview Questions which are recently asked in Tech Mahindra company. These questions are included for both Freshers and Experienced professionals.
1. Compare between Java and Python.
Java is a statically typed and compiled language, and Python is a dynamically typed and interpreted language. This single difference makes Java faster at runtime and easier to debug, but Python is easier to use and easier to read.
2. What is Python?
Python is a high-level, interpreted, interactive and object-oriented scripting language that is used to create user interface applications for web development (server side), software development, mathematics, operation and so on.
Python is a general-purpose interpreted, interactive, object-oriented programming language.
3. What are the key features of Python?
- Easy To Learn
- High-Level Programming Language
- Portable and Expressive
- Free and Open Sources
4. What is the purpose of PYTHONPATH environment variable?PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. For most installations, you should not set these variables since they are not needed for Python to run.
Python knows where to find its standard library.
5. Which data types are supported in Python?
The basic data types in Python are Integers, Floating-Point Numbers, Complex Numbers, Strings, Boolean Type, Built-In Functions like Math. Type Conversion. Iterables, Composite Data Type like Classes, Attributes, and Inheritance. Input/Output.
Interview Questions based on Experience - Click here - Python Interview Questions and Answers
6. How is memory managed in Python?
Memory management in Python involves a private heap containing all Python objects and data structures. The management of this private heap is ensured internally by the Python memory manager.
The Python memory manager has different components which deal with various dynamic storage management aspects, like sharing, segmentation, reallocation or caching
7. Explain Inheritance in Python with an example.
Inheritance is a powerful feature in object oriented programming. It refers to defining a new class with little or no modification to an existing class.
The new class is called derived (or child) class and the one from which it inherits is called the base (or parent) class.
8. 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.
9. What type of language is Python? Programming or Scripting?
Python is scripting, general-purpose, high-level, and interpreted programming language. It also provides the object-oriented programming approach.,
10. Define generators in Python?
A Python generator is a function that produces a sequence of results. It works by maintaining its local state, so that the function can resume again exactly where it left off when called subsequent times.
Thus, you can think of a generator as something like a powerful iterator.
11. How do we reverse a list in Python?
Reversing a list in-place with the list. reverse() method. Using the “ [::-1] ” list slicing trick to create a reversed copy. Creating a reverse iterator with the reversed() built-in function.
12. Write a program to check whether the given number is prime or not?
# To take input from the user num = int(input("Enter a number: ")) # prime numbers are greater than 1 if num > 1: # check for factors for i in range(2,num): if (num % i) == 0: print(num,"is not a prime number") print(i,"times",num//i,"is",num) break else: print(num,"is a prime number") # if input number is less than # or equal to 1, it is not prime else: print(num,"is not a prime number")
13.What is a dictionary in Python?
Python dictionary is an unordered collection of key-value pairs. It is mutable and can contain mixed types. The keys in a dictionary must be immutable objects like strings or numbers. They must also be unique within a dictionary.
14. 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.
15. What is a map function in Python?
Python's map() is a built-in function that allows you to process and transform all the items in an iterable without using an explicit for loop, a technique commonly known as mapping.
16. What is a Python module?
Module can be defined as functions, classes, and variables. Modules help you to organize Python code logically. By grouping related code into modules, you can make Python code more easy-to-use and understand.
17. Is indentation optional in Python?
It is required for indicating what block of code a statement belongs to. For example, j=1 and while(j<=5): is not indented, and so it is not within while block. So, Python code structures by indentation. Python uses 4 spaces as indentation by default.
18. How are Python arrays and Python lists different from each other?
Lists and arrays are used in Python to store data(any data type- strings, integers etc), both can be indexed and iterated also. Arrays need to be declared whereas lists do not need declaration because they are a part of Python's syntax. This is the reason lists are more often used than arrays.
19. What is __init__ in Python?
"__init__" is a reseved method in python classes. It is known as a constructor in object oriented concepts. This method called when an object is created from the class and it allow the class to initialize the attributes of a class.
20. Write Python code to check the given sequence is a palindrome or not?
Python program to check the given number 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!")
21. What is the use of manage.py?
Every Django project starts with a manage.py file in its root. It's a convenience script that allows you to run administrative tasks like Django's including django-admin.
22. How can I practice code?
To Practice Python effectively you have to Code Every day by write yourself in a Interactive way .Make It Collaborative With help of Others Learners. Build something using all the python concepts, techniques and modules.
23. Does multiple inheritances is supported in Python?
When a child class inherits from multiple parent classes, it is called multiple inheritance. Unlike Java and like C++, Python supports multiple inheritance.
24. How can we create an empty class in Python?
In Python, to write an empty class pass statement is used. pass is a special statement in Python that does nothing. It only works as a dummy statement. However, objects of an empty class can also be created.
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.