Python Preguntas Entrevista
Python Preguntas Entrevista
Interview Questions
with Answers to Crack
Technical Interview
*Disclaimer*
num_str = "10"
num_int = int(num_str)
Q.3 How do you check the data type of a variable
in Python?
Ans: You can use the ‘type()’ function to check the
data type of a variable. For example:
num = 10
print(type(num)) # Output: <class 'int'>
empty_dict = {}
empty_dict = dict()
Topic 2
OOPS concept in Python:
Q.1 What is OOPS and how is it implemented in
Python?
Ans: Object-Oriented Programming (OOPS) is a
programming paradigm that uses objects to
represent real-world entities. In Python, OOPS is
implemented through classes and objects. Classes
are blueprints for creating objects, and objects are
instances of a class.
Q.2 What are the four principles of OOPS?
Ans: The four principles of OOPS are:
Encapsulation: bundling of data and methods that
operate on that data within a single unit (class).
Inheritance: ability of a class to inherit properties
and methods from its parent class.
Polymorphism: ability of an object to take on
different forms or behaviors based on the context.
Abstraction: representing essential features and
hiding unnecessary details to simplify the
complexity.
Q.3 What is method overloading in Python?
Ans: Method overloading in Python refers to defining
multiple methods with the same name but different
parameters within a class. However, Python does not
support method overloading by default as it does in
languages like Java. In Python, you can achieve a
similar effect by using default arguments or using
variable-length arguments.
Q.4 What is method overriding in Python?
Ans: Method overriding in Python refers to defining a
method in a child class that already exists in its
parent class with the same name and signature. The
method in the child class overrides the method in the
parent class, providing a different implementation.
Q.5 What is the difference between a class
method and an instance method in Python?
Ans: A class method is a method bound to the class and
not the instance of the class. It is defined using the
@classmethod decorator and can access only class-
level variables. On the other hand, an instance
method is bound to the instance of the class and can
access both instance and class-level variables.
Topic 3
String handling functions:
Q.1 How do you concatenate two strings in
Python?
Ans: You can concatenate two strings using the +
operator. For example:
str1 = "Hello"
str2 = "World"
result = str1 + str2 # Output: "HelloWorld"
str1 = "hello"
uppercase_str = str1.upper() # Output: "HELLO"
str1 = "Hello,World"
substrings = str1.split(",")
in Python:
Q.1 What are control statements in Python?
Ans: Control statements are used to control the flow of
execution in a program. Common control statements
in Python include if-else, for loops, while loops, and
break/continue statements.
Q.2 How do you write an if-else statement in
Python?
Ans: An if-else statement in Python is written using the
following syntax:
if condition:
# Code block executed if the condition is
True
else:
# Code block executed if the condition is
False
Q.3 How do you define a function in Python?
Ans: A function in Python is defined using the def
keyword. For example:
def greet():
print("Hello, world!")
def greet(name):
print("Hello, " + name + "!")
a = 5
b = 10
a, b = b, a
print(a, b) # Output: 10, 5
Topic 6
Lambda functions, list
comprehension:
Q.1 What is a lambda function in Python?
Ans: A lambda function is an anonymous function defined
using the lambda keyword. It is typically used for
short, one-line functions. For example:
Bosscoder?
1000+ Alumni placed at Top
Product-based companies.
Explore More