Python Chapters 1 2 Presentation
Python Chapters 1 2 Presentation
Python
Chapters 1 & 2: Python Basics and
Flow Control
Python Basics: Overview
• • Python is a versatile, beginner-friendly
programming language.
• • Key concepts include expressions, data
types, variables, and basic syntax.
• • Interactive Shell allows testing Python
commands instantly.
Data Types and Variables
• • Fundamental Data Types:
• - Integer (e.g., 5), Float (e.g., 3.14), String
(e.g., 'Hello')
• • Variables store and manage data values.
• • Use type conversion functions like int(), str(),
and float().
Writing Your First Program
• • Python programs are a sequence of
instructions.
• • Use comments (#) to annotate your code.
• • Example:
• print('Hello, world!') # Outputs text to the
console.
Input and Output
• • Use input() to get user input:
• name = input('What is your name? ')
• • Use print() to display output:
• print(f'Hello, {name}!')
Flow Control: Overview
• • Flow control directs the execution of a
program.
• • Conditional Statements: if, elif, and else.
• • Loops: while and for, with optional break
and continue.
Conditional Statements
• • Syntax:
• if condition:
• # Code block
• elif another_condition:
• # Code block
• else:
• # Code block
• • Example:
• if age > 18:
Loops in Python
• • while Loop: Repeats as long as a condition is
true.
• Example:
• while count < 5:
• print(count)
• • for Loop: Iterates over a sequence.
• Example:
• for item in [1, 2, 3]:
• print(item)
The break and continue
Statements
• • break: Exit a loop prematurely.
• Example:
• for i in range(10):
• if i == 5:
• break
• • continue: Skip the rest of the current
iteration.
• Example:
• for i in range(5):
Summary
• • Python Basics:
• - Data types, variables, and basic syntax.
• • Flow Control:
• - Conditional statements and loops to direct
program flow.
• • Writing Python programs builds the
foundation for automation.