0% found this document useful (0 votes)
3 views2 pages

03 Python Beginner Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

03 Python Beginner Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programming

A Complete Beginner's Guide — Chapter 1 to 4

Chapter 1: Why Python?


Python is one of the most popular and versatile programming languages in the world. Its clean, readable
syntax makes it the perfect first language for beginners, while its powerful libraries make it indispensable
for professionals in data science, web development, automation, and artificial intelligence.

# Your first Python program


print("Hello, World!")
print("Python is awesome!")

■ Tip: Python files are saved with the .py extension. You can run them from the terminal with: python
[Link]

Chapter 2: Variables and Data Types


Variables are containers for storing data. Python is dynamically typed, meaning you do not need to declare
the type of a variable before assigning it. Python supports several core data types: int, float, str, bool, list,
tuple, dict, and set.

# Variables and types


name = "Alice" # str
age = 28 # int
height = 1.72 # float
is_student = True # bool
print(type(name)) #

■ Tip: Use type() to inspect the data type of any variable at runtime.

Chapter 3: Control Flow


Control flow structures allow your program to make decisions (if/elif/else) and repeat actions (for/while
loops). Mastering these is essential to writing any meaningful program.

# If-else example
score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
else:
print("Grade: C")

# For loop
for i in range(1, 6):
print(f"Count: {i}")

■ Tip: Python uses indentation (4 spaces) to define code blocks — no curly braces needed!

Chapter 4: Functions
Functions allow you to encapsulate reusable logic. Defining a function with def and calling it by name
keeps your code DRY (Don't Repeat Yourself). Functions can accept parameters and return values.

# Defining and calling functions


def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"

print(greet("Bob")) # Hello, Bob!


print(greet("Sue", "Good morning")) # Good morning, Sue!

■ Tip: Default parameter values make your functions more flexible and easier to use.

You might also like