1
1
• Python is a popular, high-level programming language known for its simplicity and
readability.
• It is versatile, used in web development, data analysis, machine learning, automation, and
more.
Code Example:
python
Copy
print("Hello, Python!")
2: Installing and Setting Up Python
• Download the latest version of Python from the official website: python.org.
• Install an Integrated Development Environment (IDE) such as PyCharm or Visual Studio Code.
• Python comes with an interactive shell called IDLE, which can also be used to run code.
• Make sure Python is added to your system's PATH during installation for easy access.
Code Example:
bash
Copy
python –version
3: Python Syntax and Code Structure
• Python uses indentation (spaces or tabs) to define blocks of code, instead of curly braces {}.
• Python does not require semicolons to end statements, making code cleaner and easier to
read.
• Statements can span multiple lines, making it more flexible for writing readable code.
Code Example:
python
Copy
def greet(name):
print(f"Hello, {name}!")
greet("Python")
4: Variables and Data Types
• Variables store data, and Python automatically infers the data type based on the value
assigned.
• Common data types include integers (int), floating-point numbers (float), strings (str), and
booleans (bool).
Code Example:
python
Copy
x=5 # int
Code Example:
python
Copy
a = 10
b = 20
# Arithmetic
sum = a + b
# Comparison
result = a < b
# Logical
• You can use built-in functions like int(), float(), and str() to perform type casting.
Code Example:
python
Copy
x = "10" # string
z = 5.7 # float
• The if block executes if the condition is true; otherwise, the else block runs.
Code Example:
python
Copy
x = 10
if x > 5:
else:
• for loop is used for iterating over a sequence like a list or range.
Code Example:
python
Copy
for i in range(5):
print(i)
x=0
while x < 5:
print(x)
x += 1
9: Break, Continue, and Pass Statements
• continue: Skips the current iteration and moves to the next one.
• pass: A placeholder that does nothing, useful for stubbing out code.
Code Example:
python
Copy
# break example
for i in range(10):
if i == 5:
break
print(i)
# continue example
for i in range(5):
if i == 3:
continue
print(i)
# pass example
def empty_function():
pass
10: Functions and Function Arguments
• You can pass data to functions via arguments and return values using return.
Code Example:
python
Copy
def greet(name="User"):
print(f"Hello, {name}!")
greet("Alice")