Python Programming - Beginner's Handout
1. Introduction to Python
Python is a popular, beginner-friendly programming language.
Known for its simplicity and readability.
Used for web development, data analysis, AI, scientific computing, and more.
2. Python Basics
a) Running Python
Install Python from [Link].
Use an IDE (like PyCharm, VS Code) or a simple text editor.
Run Python code:
o In the Python interpreter (>>>).
o By saving code in a .py file and running python [Link] in the terminal.
b) Basic Syntax
Python uses indentation (not braces {} or semicolons ;)
*********************************************************************
if 5 > 3:
print("5 is greater than 3") # Indented block
**********************************************************************
c) Comments
Use # for single-line comments.
Use triple quotes for multi-line comments.
*****************************************************************
# This is a single-line comment.
"""
This is a multi-line comment.
"""
****************************************************************
3. Variables and Data Types
a) Variables
Used to store data.
No need to declare types explicitly.
***********************************************************************
x=5 # Integer
y = 3.14 # Float
name = "Alice" # String
**************************************************************************
b) Data Types
Common types: int, float, str, bool, list, dict.
is_python_easy = True # Boolean
fruits = ["apple", "banana", "cherry"] # List
****************************************************************************
4. Input and Output
a) Output
Use print() to display output.
print("Hello, World!")
print("Sum =", 5 + 3)
b) Input
Use input() to take user input.
Convert input to the desired type.
name = input("Enter your name: ")
age = int(input("Enter your age: ")) # Converts input to integer
print("Hello", name, "you are", age, "years old.")
**************************************************************************
5. Operators
Arithmetic Operators: +, -, *, /, //, %, **.
Comparison Operators: ==, !=, <, >, <=, >=.
Logical Operators: and, or, not.
****************************************************
Example:
a = 10
b=3
print(a + b) # Addition
print(a > b and b > 1) # Logical AND
**********************************************************************
6. Control Flow
a) If-Else Statements
Use if, elif, and else for decision-making.
*************************************************************
x = 10
if x > 5:
print("x is greater than 5")
elif x == 5:
print("x is equal to 5")