Python Internal
Python Internal
2. Python List:
A list in Python is a collection of items that are ordered and changeable. It allows duplicate
values and can contain different data types. Lists are created using square brackets LJ'.
Example:
python OCopy code
3. Python Tuple:
A tuple is similar to a list but is immutable, meaning its elements cannot be changed after
creation. Tuples are created using parentheses 0.They are often used to group related
data.
Example:
python Copy code
Example:
python Copy code
my_set = (1, 2, 3, 3, 4, 5)
print (my_set) # Output: (1, 2, 3, 4, 5)
5. Conditional Statements:
Conditional statements in Python allow you to control the flow of your program based on
certain conditions. These are if,'elif' (else if), and 'else.
Example:
python O Copy code
age = 25
6. Exception Handling:
Exception handling in Python allows you to gracefully deal with errors or exceptions that
might occur during program execution. It involves try', 'except', 'else', and finally '
blocks.
Example:
python Copy code
try:
result = 10/0
except ZeroDivisionError as e:
print(f"Error: (e)")
7. Assert Statement:
The 'assert statement is used to test conditions that should always be true. If the condition
is false, it raises an AssertionError.
Example:
python Copy code
X = 2
assert x == 1, "x should be 1"
8. Multiple Inheritance:
Multiple inheritance in Python allows a class to inherit attributes and methods from multiple
base classes. It's achieved by listing the parent classes in the class definition.
Example:
python O Copy code
class A:
def method_ a(self) :
print ("Method A")
class B:
class C(A, B) :
pass
obj_c = C)
obj_c.method_a()
obj_c.method_b()
9. Constructor in Python:
A
constructor in Python is a special method (' ._init__)that gets called when an object of a
class is instantiated. It's used to initialize the object's attributes.
Example:
python 9 Copy code
class Person:
def init__(self, name, age):
self. name = name