You are on page 1of 3

Chapter 1: Introduction to Python

Python is a high-level, interpreted programming language that is widely used for web development,
scientific computing, data analysis, artificial intelligence, and many other applications. In this
chapter, we will cover the basics of Python and how to get started with writing and running Python
programs.

Section 1.1: Installing Python

To get started with Python, you first need to download and install it on your computer. Here are the
steps for installing Python on Windows:

Go to the official Python website at www.python.org

Click on the "Downloads" button in the navigation menu

Select the appropriate version of Python for your operating system (e.g., Windows, Mac, or Linux)

Download the installer and run it on your computer

Follow the installation wizard to complete the installation process

Once Python is installed, you can open a command prompt or terminal window and type "python" to
start the Python interpreter.

Section 1.2: Writing and Running Your First Python Program

Let's write a simple "Hello, World!" program to get started:

print("Hello, World!")
To run this program, open a command prompt or terminal window, navigate to the directory where
the program is saved, and type "python hello.py" (assuming the file is named hello.py). You should
see the message "Hello, World!" printed to the console.

Section 1.3: Variables, Data Types, and Operators

Python has several built-in data types, including integers, floating-point numbers, strings, and
booleans. Let's create some variables and assign them different data types:
# Integer
age = 25

# Floating-point number
price = 4.99

# String
name = "Alice"

# Boolean
is_student = True
We can also perform mathematical and comparison operations using Python's operators:

# Mathematical operations
x = 10 + 5 # addition
y = 20 - 10 # subtraction
z = 5 * 6 # multiplication
w = 10 / 2 # division

# Comparison operations
a = 10 == 5 # equal to
b = 20 != 10 # not equal to
c = 5 > 2 # greater than
d = 10 < 20 # less than
Section 1.4: Control Flow

Python has several control flow statements that allow us to execute different blocks of code
depending on certain conditions. Here are some examples:

# if-else statement

if age >= 18:

print("You are an adult.")


else:

print("You are a minor.")

# while loop

i=0

while i < 5:

print(i)

i += 1

# for loop

fruits = ["apple", "banana", "orange"]

for fruit in fruits:

print(fruit)

You might also like