0% found this document useful (0 votes)
2 views12 pages

Introduction To Python Programming

This document provides an introduction to Python programming, highlighting its simplicity, versatility in web development, data science, and AI. It covers Python basics such as variables, data types, string manipulation, arithmetic operations, and user input/output. The document emphasizes Python's beginner-friendly nature and includes practical exercises for learners.

Uploaded by

ragheeds0haidar
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)
2 views12 pages

Introduction To Python Programming

This document provides an introduction to Python programming, highlighting its simplicity, versatility in web development, data science, and AI. It covers Python basics such as variables, data types, string manipulation, arithmetic operations, and user input/output. The document emphasizes Python's beginner-friendly nature and includes practical exercises for learners.

Uploaded by

ragheeds0haidar
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

Introduction to Python Programming

Prepared by: Ms. Faten Chahine


What is Python?
Python is a high-level programming language designed with simplicity and readability in
mind. Created by Guido van Rossum in 1991, it has become one of the most widely used
languages in the world.

Web Development
Python powers popular websites and web frameworks like Django and Flask, making it a top
choice for building web applications.

Data Science & AI


Widely used in data science, machine learning, and artificial intelligence with libraries like
NumPy, Pandas, and TensorFlow.

Beginner Friendly
Python's clean syntax reads almost like English, making it the ideal first programming
language for new learners.
CHAPTER 1

Python Basics — Variables and Data Types


What is a Variable? Examples in Code
A variable is a named container that stores information your program
can reference and manipulate later. Think of it as a labeled box where
you put a value.

Core Data Types


Integers (int) — Whole numbers like 5, -3, 100
Floats (float) — Decimal numbers like 3.14, -0.5
Strings (str) — Plain text like "Hello"
Boolean (bool) — True or False values

Strings (str) Numbers


Plain text values Whole or decimal

Boolean
True / False
Practice — Modifying Variables
Now it's your turn! Let's practice changing the values of variables. Follow the two exercises below and update the code accordingly.

Exercise 1 Exercise 2

« Replace the name George with John

« Replace the age 70 with 35

« Replace the name John with Dani

« Replace the age 35 with 50


CHAPTER 2

Working With Strings


Strings are one of the most commonly used data types in Python. Let's explore some essential string operations that you'll use frequently in your programs.

Creating & Formatting Strings Concatenation


Use the newline character \n to move text to another line within a string. You can also Concatenation means joining two or more strings together using the + operator. The
assign strings to variables for reuse throughout your code. backslash \ is called an escape character.

Finding String Length


Use the len() function to count the number of characters in a string, including spaces.

Finding the letter at a certain index


String Functions
Python provides powerful built-in functions that let you manipulate strings with ease. One of the most useful is the .replace() method, which swaps one
word or phrase in a string for another.

Replace a word in a string with another word

The .replace(old, new) function searches for the specified text and replaces it. This does not modify the original string — it returns a new one. Here are
some examples:

💡 Tip: String functions like .replace(), .upper(), and .lower() are called methods — they use dot notation because they belong to the string
object itself.
CHAPTER 3

Working with Numbers


Whole and Decimal Numbers
Python handles different types of numbers with ease. Let's explore the key number types and arithmetic operations you'll use in your programs.

Whole Numbers (int) Negative Numbers

Decimal Numbers (float)

Order with Parentheses

Use parentheses to control the order of operations, just like in math class.
Convert Number to String
Modulus (Remainder) Use str() to convert a number into a string so you can concatenate it with text.
The % operator returns the remainder when dividing two numbers.

Python supports all standard arithmetic operators: + (add), - (subtract), * (multiply), / (divide). You can combine these with parentheses to build complex equations.
Functions Related to Numbers
Python includes several handy built-in functions for working with numbers. These save you from writing complex math logic yourself. Let's look at the most important
ones.

abs() — Absolute Value pow() — Power


Returns the positive version of any number, removing the negative sign. Raises a number to the power of another. For example, pow(2, 3) equals 8 (2 × 2 ×
2).

min() — Minimum Value round() — Rounding


Finds the smallest number in a set of values. Rounds a decimal number to the nearest whole number, or to a specified number
of decimal places.

max() — Maximum Value


Finds the largest number in a set of values.
Importing Math Functions
Some advanced math functions aren't built into Python directly — you need to import them from the math module first using import math. This
gives you access to powerful tools for rounding and calculations.

1 2 3

floor() — Round Down ceil() — Round Up sqrt() — Square Root


Chops off the decimal part and always Always rounds a number up to the Returns the square root of a number. For
rounds down to the nearest whole nearest whole number. For example, example, [Link](16) returns 4.0.
number. For example, [Link](3.9) [Link](3.1) returns 4.
returns 3.

📌 Remember: Always add import math at the top of your Python file before using [Link](), [Link](), or [Link]().
CHAPTER 4

Getting Input from Users


Input & Output in Python
One of the most important skills in programming is communicating with the user. Python makes this simple with two core functions:

input() print()
Reads text that the user types into the console. You can include a prompt message Displays output to the screen. You can print text, variables, or combine them using
inside the parentheses to tell the user what to enter. concatenation or f-strings.

Example Code

In this example, the program asks the user for their name and age, then displays a personalized greeting. Notice how input() always returns a string — you'll need to convert it with
int() if you want to use it as a number.
Basic Arithmetic Operations
Python can serve as a powerful calculator! Here are the five fundamental arithmetic operators you need to know. These form the backbone of nearly every calculation you'll perform in your programs.

+ Addition
1 Adds two values together

- Subtraction
2 Subtracts one value from another

* Multiply
3 Multiplies two values

/ Division
4 Divides and returns a float

% Modulus
5 Returns the remainder

See It in Action
Thank You! ï

Great job making it through today's lesson on Python fundamentals! You've learned
about variables, data types, strings, numbers, functions, input/output, and arithmetic
operations — that's a lot of ground covered.

If you have any questions, please do not hesitate to let me know! Practice makes
perfect — keep coding! c

You might also like