1. What is Python?
Python is a high-level, interpreted programming language known for its simplicity and readability. It
supports multiple programming paradigms, including procedural, object-oriented, and functional
programming.
2. What is a Platform?
A platform refers to the underlying hardware or software environment in which a program runs. Examples
include Windows, macOS, Linux, etc.
3. Platform Independent vs. Portability
• Platform Independent: A language or program that can run on different platforms without
modification. Python is platform-independent because its code can run on various operating systems
with the same interpreter.
• Portability: The ability of software to be transferred from one environment to another with minimal
changes. Portability is a feature that allows Python programs to run on different systems with little to
no modification.
Difference:
Platform independence means the code itself doesn't need to change to run on different platforms.
Portability means that the code can be easily modified to run on different platforms if necessary.
4. What is an Object and Class?
• Class: A blueprint for creating objects (instances). It defines a set of attributes and methods that the
objects created from the class can have.
• Object: An instance of a class that has specific values for the attributes defined by the class.
Example:
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
my_dog = Dog("Buddy", "Golden Retriever")
5. Why We Need a Constructor?
A constructor is used to initialize the object's state when it is created. In Python, the constructor is defined
using the __init__ method.
6. Explain the Creation of an Object
An object is created by instantiating a class. When you call the class, Python automatically invokes the
__init__ method to initialize the object.
Example:
my_object = MyClass()
, 7. What is a Variable? Types of Variables
• Variable: A storage location identified by a name that holds data.
• Types of Variables:
o Instance Variables: Belong to the object and are specific to each instance.
o Class Variables: Shared among all instances of the class.
Example:
class Car:
wheels = 4 # Class variable
def __init__(self, color):
self.color = color # Instance variable
my_car = Car("Red")
8. What is a Method? Types of Methods
• Method: A function defined within a class.
Types of Methods:
o Instance Methods: Operate on an instance of the class.
o Class Methods: Operate on the class itself.
o Static Methods: Do not operate on the class or its instances.
Example:
class MyClass:
def instance_method(self):
pass
@classmethod
def class_method(cls):
pass
@staticmethod
def static_method():
pass
9. Actual Parameters vs. Formal Parameters
• Actual Parameters: The values passed to a function when it is called.
• Formal Parameters: The variables defined by the function that receive the actual parameters.
Example:
def greet(name): # name is a formal parameter
print(f"Hello, {name}!")
greet("Alice") # "Alice" is an actual parameter
10. Default Argument and Keyword Argument
• Default Argument: An argument that assumes a default value if not provided.
• Keyword Argument: An argument passed by explicitly specifying the parameter name.
Example:
Python is a high-level, interpreted programming language known for its simplicity and readability. It
supports multiple programming paradigms, including procedural, object-oriented, and functional
programming.
2. What is a Platform?
A platform refers to the underlying hardware or software environment in which a program runs. Examples
include Windows, macOS, Linux, etc.
3. Platform Independent vs. Portability
• Platform Independent: A language or program that can run on different platforms without
modification. Python is platform-independent because its code can run on various operating systems
with the same interpreter.
• Portability: The ability of software to be transferred from one environment to another with minimal
changes. Portability is a feature that allows Python programs to run on different systems with little to
no modification.
Difference:
Platform independence means the code itself doesn't need to change to run on different platforms.
Portability means that the code can be easily modified to run on different platforms if necessary.
4. What is an Object and Class?
• Class: A blueprint for creating objects (instances). It defines a set of attributes and methods that the
objects created from the class can have.
• Object: An instance of a class that has specific values for the attributes defined by the class.
Example:
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
my_dog = Dog("Buddy", "Golden Retriever")
5. Why We Need a Constructor?
A constructor is used to initialize the object's state when it is created. In Python, the constructor is defined
using the __init__ method.
6. Explain the Creation of an Object
An object is created by instantiating a class. When you call the class, Python automatically invokes the
__init__ method to initialize the object.
Example:
my_object = MyClass()
, 7. What is a Variable? Types of Variables
• Variable: A storage location identified by a name that holds data.
• Types of Variables:
o Instance Variables: Belong to the object and are specific to each instance.
o Class Variables: Shared among all instances of the class.
Example:
class Car:
wheels = 4 # Class variable
def __init__(self, color):
self.color = color # Instance variable
my_car = Car("Red")
8. What is a Method? Types of Methods
• Method: A function defined within a class.
Types of Methods:
o Instance Methods: Operate on an instance of the class.
o Class Methods: Operate on the class itself.
o Static Methods: Do not operate on the class or its instances.
Example:
class MyClass:
def instance_method(self):
pass
@classmethod
def class_method(cls):
pass
@staticmethod
def static_method():
pass
9. Actual Parameters vs. Formal Parameters
• Actual Parameters: The values passed to a function when it is called.
• Formal Parameters: The variables defined by the function that receive the actual parameters.
Example:
def greet(name): # name is a formal parameter
print(f"Hello, {name}!")
greet("Alice") # "Alice" is an actual parameter
10. Default Argument and Keyword Argument
• Default Argument: An argument that assumes a default value if not provided.
• Keyword Argument: An argument passed by explicitly specifying the parameter name.
Example: