Python Syntax and Constructs OOP (1)
Python Syntax and Constructs OOP (1)
T O O U R
P R E S A N T A T I O N
Applying
Python
Syntax and
Constructs
UNDERSTANDING PYTHON SYNTAX, VARIABLES,
CONTROL STRUCTURES, AND MORE IN OOP
Agenda
Case sensitivity
Indentation for blocks (e.g., loops, functions)
Commenting: Single-line (#) and Multi-line ('''
''')
File naming conventions
Python Syntax Example
Example:
# Single-line comment
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
Variables and Data Types
Example:
x = 10 # int
y = 3.14 # float
z = "Hello" # str
Writing Expressions
x = 10
y = 20
sum = x + y
is_greater = x > y
Input and Output
if x > y:
print("x is greater")
else:
print("y is greater")
Object-Oriented
Programming in Python
- Classes and Objects
- Encapsulation, Inheritance, Polymorphism
- Example:
class Car:
def __init__(self, make, model):
self.make = make
self.model = model
Class and Object
Example
class Car:
def __init__(self, make, model):
self.make = make
self.model = model