WELCOME
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
1. Python Syntax Overview
2. Variables and Data Types
3. Writing Expressions
4. Input and Output
5. Control Structures in OOP Context
Python Syntax Overview
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
- Variables are containers for data.
- Data types: int, float, str, bool, list, tuple, dict,
set
- Python is dynamically typed: No need to
declare type.
Example:
x = 10 # int
y = 3.14 # float
z = "Hello" # str
Writing Expressions
- Python supports arithmetic, logical, and
relational operators.
- Example:
x = 10
y = 20
sum = x + y
is_greater = x > y
Input and Output
- Use `input()` for user input.
- Use `print()` for output.
- Example:
name = input("Enter your name: ")
print(f"Hello, {name}!")
Control Structures
- Conditional Statements: if, elif, else
- Loops: for, while
- Example:
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
car1 = Car("Toyota", "Corolla")
print(car1.make)