Hi guys!
Let's start our Python Interview Preparation Series today, covering the most important questions frequently asked in interviews.
We'll start with the basics and gradually move towards intermediate and advanced-level questions.
Let's get started!
Q1. What is Python?
Python is a high-level, interpreted, general-purpose programming language known for its simple syntax and readability.
Q2. What are the main features of Python?
- Easy to learn and understand.
- Interpreted language.
- Dynamically typed.
- Object-oriented programming support.
- Open-source and free.
- Large collection of libraries.
- Cross-platform compatibility.
Q3. Is Python compiled or interpreted?
Python is generally considered an interpreted language.
In CPython, source code is first compiled into bytecode, which is then executed by the Python Virtual Machine (PVM).
Q4. What is a variable in Python?
A variable is a name used to store or refer to a value.
Example:
name = "John"
age = 25
print(name)
print(age)Q5. What are the different data types in Python?
Python has several built-in data types:
- int – Integer
- float – Decimal numbers
- str – Strings
- bool – Boolean values
- list – Ordered, mutable collection
- tuple – Ordered, immutable collection
- set – Collection of unique elements
- dict – Key-value pairs
- complex – Complex numbers
Q6. What is the difference between a list and a tuple?
List:
- Mutable (can be modified).
- Uses square brackets
[].- Supports adding and removing elements.
Tuple:
- Immutable (cannot be modified).
- Uses parentheses
().- Does not support item reassignment.
Q7. What is the difference between == and is in Python?
-
== checks whether two objects have equal values.-
is checks whether two references point to the same object.Example:
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b) # True
print(a is b) # FalseQ8. What is indentation in Python?
Indentation refers to the spaces at the beginning of a code line.
Python uses indentation to define blocks of code.
Example:
age = 20
if age >= 18:
print("Eligible to vote")Q9. What is the difference between mutable and immutable data types?
Mutable: Objects whose values can be changed after creation.
Examples: List, Dictionary, Set.
Immutable: Objects whose values cannot be changed after creation.
Examples: Integer, Float, String, Tuple, Boolean.
Q10. How do you take input from a user in Python?
Python uses the
input() function to accept user input.Example:
name = input("Enter your name: ")
print("Hello", name)Remember: The
input() function returns a string by default.Double Tap ❤️ for Part 2!