0% found this document useful (0 votes)
38 views42 pages

Module 2

This document provides an introduction to Python, covering its history, key features, and reasons to study it, highlighting its simplicity, versatility, and growing popularity. It also outlines Python's basic concepts, including variables, data types, operators, input/output, and control flow, essential for beginners to understand programming in Python. The document emphasizes Python's applications across various fields such as web development, data science, and automation.

Uploaded by

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

Module 2

This document provides an introduction to Python, covering its history, key features, and reasons to study it, highlighting its simplicity, versatility, and growing popularity. It also outlines Python's basic concepts, including variables, data types, operators, input/output, and control flow, essential for beginners to understand programming in Python. The document emphasizes Python's applications across various fields such as web development, data science, and automation.

Uploaded by

Mohamed Romance
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Module 2: Introduction to Python

 History and Origin of Python

 What is Python? (Simple, General Purpose, High-Level)

 Why Study Python? (Easy, Growing, Versatile)

 Key Features of Python (Simple Syntax, Open Source, Platform Independent)

 Python Versions
📖 History and Origin of Python
Introduction
Python is a high-level, interpreted programming language that has gained significant global
popularity due to its simplicity, readability, and wide range of applications. Understanding its
historical background provides valuable insight into the language's design philosophy, evolution,
and current role in software development and data science.
🏁 Development and Background
Python was developed by Guido van Rossum, a Dutch computer programmer, in the late 1980s and officially
released in 1991. At the time, van Rossum was working at the Centrum Wiskunde & Informatica (CWI) in the
Netherlands.
He had been using the ABC programming language, a teaching language known for its simplicity and ease of
learning. However, he found it limiting for broader software development. Drawing inspiration from ABC and
aiming to design a language that combined clarity, power, and extensibility, van Rossum began creating Python
during his 1989 Christmas holidays
🐍 Origin of the Name
Despite common assumptions, the name “Python” does not originate from the
snake. Instead, it was inspired by “Monty Python’s Flying Circus”, a British
comedy series that van Rossum enjoyed. He selected the name “Python” to
reflect the language’s design goal of being fun and engaging to use, alongside
being powerful.
🗂Timeline of Python Versions
Version Release Year Key Features
Initial release with basic core
Python 1.0 1991 features such as exception handling
and functions
Introduced garbage collection and
Python 2.0 2000
list comprehensions
Major redesign, not backward
Python 3.0 2008 compatible with Python 2; improved
Unicode support

Current stable version (as of


Python 3.12 2024 February 2024), with enhancements
in performance and syntax features
What is Python? (Simple, General Purpose, High-Level)
🔍 Definition
Python is a widely-used, open-source, high-level programming language known for its simplicity, readability, and
versatility. It was created by Guido van Rossum and first released in 1991. Python is used in a broad range of
fields, including web development, data science, machine learning, automation, and software development.
Key Characteristics of Python
✅ 1. Simple
Python is designed to be easy to read and write. Its syntax is clear and concise, making it an excellent language for
beginners and educators.
print("Welcome to Python programming!")
✅ 2. General-Purpose
✅ 2. General-Purpose
Python is a general-purpose language, which means it is not limited to one specific type of task. It
can be used to build:
Websites
Desktop applications
Mobile apps
Games
Machine learning models
IoT and robotics systems
Scientific computing platforms
🎓 Why Study Python? (Easy, Growing, Versatile)
Introduction
Python is one of the most popular programming languages in the world today. It is widely taught in schools,
colleges, and professional training programs due to its unique combination of simplicity, power, and real-world
usefulness. Here are three key reasons why every beginner — and even advanced learners — should study
Python:
✅ 1. Python is Easy to Learn
🔹 Simple and Readable Syntax:
Python’s code looks like English, which makes it easier to write and understand.
You don’t need to write a lot of code to perform a task. 🔹 Beginner-Friendly:
•No prior programming experience needed.
Example:
•Python is often the first language taught to new coders.
print("Learning Python is fun!")
🚀 2. Python is Fast-Growing
and In-Demand
🔹 Rapid Adoption Worldwide:
Python has been ranked among the top programming languages globally by surveys such as TIOBE and Stack
Overflow.
Its popularity continues to grow in both academia and industry.
🔹 Career Opportunities:
Python is used by leading companies like:
Google Job roles that require Python include:
Facebook •Software Developer
•Data Scientist
NASA •Machine Learning Engineer
Netflix •Web Developer
IBM
🔄 3. Python is Versatile
Python is a general-purpose language, meaning it can be used in almost every field of technology.
🌐 Where Python is Used:
Area Use
Web Development Build websites and web apps (e.g., using Django, Flask)
Data Science Analyze data, create graphs, and build models
Machine Learning & AI Create smart applications (e.g., face recognition)
Game Development Design 2D and 3D games (e.g., using PyGame)
Automation Write scripts to automate boring or repetitive tasks
Cybersecurity Analyze malware, automate security tests
Robotics and IoT Control hardware using Python on devices like Raspberry P
Key Features of Python (Simple Syntax, Open Source,
Platform Independent)
Python is not just a programming language — it's a powerful, flexible, and elegant tool for solving problems.
Whether you're a beginner or a professional developer, Python stands out because of how easy, free, and universal
it is. Let’s explore the three most important features that make Python one of the world’s most loved programming
languages.
✨ 1. Simple Syntax
✅ What it means:
Python code looks and feels like plain English. It’s designed to be easy to read, write, and understand — even for
people new to programming.
Example:
for i in range(3):
print("Hello, Python!")
💎 2. Open Source
✅ What it means:
Python is completely free to download, use, and share. Anyone can see its source code, suggest
improvements, or build tools with it.
🔍 Why it matters:
No license fee — ever
A huge global community keeps improving it
Thousands of free libraries are available for everything from AI to web development
🌐 Real-world impact:
Many of the world’s biggest companies — like Google, Netflix, and NASA — use Python in real
projects, and they contribute back to the communit
🌍 3. Platform Independent
✅ What it means:
Python works anywhere — Windows, Mac, Linux, or even in the cloud. You write your code
once and it runs almost everywhere.
🔍 Why it matters:
No need to rewrite your code for different systems
Perfect for building applications that work across devices and platforms
Helps teams and companies collaborate more easily
Example:
print("Runs on any platform!")
Module 3: Python Basics

 Variables and Data Types (Integers, Floats, Strings, Booleans)

 Operators (Arithmetic, Comparison, Logical)

 Input and Output

 Basic Control Flow (if, else, elif statements)


Python Basics
In this module, you will learn the fundamental building blocks of Python programming. These
basics are essential to writing your own programs, understanding how code works, and solving
real-world problems using Python.
Whether you want to build apps, analyze data, or automate tasks — it all starts here.
📘 Variables and Data Types in Python
In programming, the effective use of variables and understanding of data types
is fundamental. Python, being a dynamically typed and high-level programming
language, allows the creation and manipulation of variables with ease and
flexibility.
This section introduces the concept of variables and the four primary data types
in Python: integers, floats, strings, and booleans, which together form the
backbone of data representation and processing in Python programs.
2. What is a Variable?
A variable in Python is a named identifier used to store data values in memory. It acts as a reference or pointer to
a location in memory where the data is held.
✅ Key Characteristics:
Variables do not need explicit declaration of type.
Python automatically assigns the data type at runtime (dynamic typing).
Variable names must begin with a letter or underscore, followed by letters, digits, or underscores.
🔍 Example:
x = 10 # Integer
name = "Alice" # String
📂 3. Data Types in Python
Python provides several built-in data types. Below are the four most commonly used primitive types for
foundational programming:
Integer (int)
The int type represents whole numbers, both positive and negative, without any decimal points.

✅ Example:
age = 18
print("My age is:", age)
Float (float)
The float type represents real numbers (numbers containing decimal points).
✅ Example:
python
temperature = 36.6
price = 99.99
String (str)
A String is a sequence of characters enclosed in either single or double quotes.

✅ Example
python
greeting = "Hello, world!"
char = 'A'

name = “Filsan"
print("Hello, " + name)
Boolean (bool)
A boolean represents one of two values: True or False. It is used primarily in control
flow, decision-making, and logical expressions.
✅ Example
python
is_student = True
print("Are you a student?", is_student)
📊 4. Type Identification and Conversion

Python provides the built-in type() function to identify a variable’s data type, and functions like int(),
float(), str(), and bool() for explicit type casting.

✅ Example name = "John"


python age = 20
x = 5.7 print(name + " is " + str(age) + " years old.")
print(type(x)) # Output: <class 'float'>
x = int(x)
print(type(x)) # Output: <class 'int'>
📚 5. Summary Table

Data Type Syntax Example Description Use Cases


Counting, indexing,
int x = 100 Whole numbers
iteration

Scientific, financial,
float x = 12.5 Decimal-point numbers
statistical apps

Messages, file names, user


str x = "Python" Textual data
input

Logical values (True or Conditional statements,


bool x = True
False) flags
Sequence Data Types
Sequences in python are objects that can store a group of values. The below data types are called sequences.
String
List 1. String Data Type: A string is a group of characters enclosed within
Tuple single quotes ('...'), double quotes ("..."), or triple quotes ('''...''' or
Set """..."""). You choose the type of quotes depending on whether your
Dictionary text contains apostrophes or quotes.
# Using triple quotes when the
string contains both kinds of
# Using double quotes when an quotes:
# Using single quotes:
apostrophe is inside the string:
text1 = 'My name is John' text3 = '''"John's book is
text2 = "This is John's book" awesome." Michael J.'''
print(text1)
print(text2) print(text3)
print(type(text1))
print(type(text2)) print(type(text3))
2. List Data Type

Lists store multiple values (which can be of different types) inside square brackets. Lists
are mutable, so you can add or remove elements.

details_list = [1, 'John', 9.5, 'pass', 1]


print(details_list)
print(type(details_list))
[1, 'John', 9.5, 'pass', 1]
<class 'list'>
3. Tuple Data Type
Tuples store multiple values, similar to lists, but they are immutable (unchangeable) once created.
Tuples are defined using parentheses.

details_tuple = (1, 'John', 9.5, 'pass', 1)


print(details_tuple)
print(type(details_tuple))

(1, 'John', 9.5, 'pass', 1)


<class 'tuple'>
4. Set Data Type
Sets store unordered, unique elements. You define a set using curly braces. Note that duplicate
elements are automatically removed.
details_set = {'pass', 1, 9.5, 'John'}
print(details_set)
print(type(details_set))
{'pass', 1, 9.5, 'John'}
<class 'set'>
5. Dictionary Data Type

Dictionaries store data as key-value pairs and are defined using curly braces with colon separators.
They are useful for pairing related values (like an athlete's name with their rank).

race = {2: 'John', 1: 'Mike', 3: 'Dani'}


print(race)
print(type(race))

{2:'John', 1: 'Mike', 3: 'Dani'}


<class 'dict'>
⚙️Operators in Python
What is an Operator?
An operator is a symbol or keyword used to perform an action on values or variables.
Python supports many types of operators, but here we’ll focus on the three most common
and important ones:
Arithmetic Operators – for calculations
Comparison Operators – for checking conditions
Logical Operators – for combining conditions
1 Arithmetic Operators
1️⃣
Used to perform basic math operations.
Operator Description Example Output
+ Addition 3+2 5

- Subtraction 5-1 4

* Multiplication 4*2 8

/ Division 10 / 2 5.0

// Floor division 7 // 2 3

% Modulus (remainder) 7%2 1

** Exponentiation 2 ** 3 8
✅ Example
a = 10
b=3
print(a + b) # 13
print(a % b) # 1
22️⃣ Comparison
Operators
Used to compare two values. They always return a boolean
result: True or False.
Operator Meaning Example Output
== Equal to 5 == 5 True
!= Not equal to 4 != 3 True
> Greater than 7>2 True
< Less than 2<1 False

>= Greater than or equal to 5 >= 5 True

<= Less than or equal to 3 <= 5 True


✅ Example:
python
x = 10
y=7
print(x > y) # True
print(x == y) # False
3️⃣ Logical Operators
Used to combine multiple conditions. Often used in if statements
.

Operator Meaning Example Output


and True if both are True True and True True
True if at least one is
or True or False True
True
not Reverses the result not True False
✅ Example:
python
age = 20
has_ID = True
print(age >= 18 and has_ID) # True
print(age < 18 or has_ID) # True
print(not has_ID) # False
Input and Output in Python
In programming, Input and Output refer to how a program interacts with the outside world
especially the user.
Input means taking data from the user.
Output means displaying results or messages to the user.
📥 Input in Python ( input() )
The input() function is used to get data from the user.
Example:
📌 What happens here?
python  The program shows a message: What
name = input("What is your name? ") is your name?
 The user types something (e.g.,
print("Hello,", name)
“Sara”)
 Python stores it in the variable name
 Then prints: Hello, Sara
Input with Type Conversion
If you need a number, convert the input like this:
age = int(input("Enter your age: "))
print("Next year you will be", age + 1)
Here, int() converts the input from string
to integer.
Output in Python (print())
The print() function is used to display messages or results on the screen.
Example ✅ You can
python Print text, numbers, or variables
print("Welcome to Python!") Combine them using commas or +

name = "Ali"
print("Hi", name)
# OR
print("Hi " + name)
🔁 4. Combining Input and Output
python
city = input("Which city are you from? ")
print ("Wow, I've always wanted to visit", city)
This small program:
Asks a question
Takes user input
Displays a friendly response
Basic Control Flow (if, else, elif statements)
What Is Basic Control Flow?
Control flow in Python determines the order in which your code is executed based on
conditions. The primary statements for this are:

if statement: Checks a condition. If it's True, the code block following it runs.

elif statement: Short for "else if." It checks another condition if the previous if (or any
preceding elif) wasn't True.

else statement: Executes a block of code when none of the previous conditions are met.
Example: Checking if a Number is Positive, Negative, or Zero
# Ask the user to input a number.
number = int(input("Enter a number: "))
# Check the number's value.
Explanation
if number > 0:
The program asks for a number and converts it to
print("The number is positive.") an integer.
The if statement checks whether the number is
elif number < 0:
greater than zero.
print("The number is negative.") The elif statement checks if the number is less than
zero.
else:
The else statement catches all other cases in this
print("The number is zero.") example, when the number is exactly zero.

You might also like