Introduction to Python Programming BPLCK105B
PYTHON MODULE 1 NOTES
Syllabus: Python Basics: Entering Expressions into the Interactive Shell, The Integer, Floating-Point, and
String Data Types, String Concatenation and Replication, Storing Values in Variables, Your First Program,
Dissecting Your Program, Flow control: Boolean Values, Comparison Operators, Boolean Operators,Mixing
Boolean and Comparison Operators, Elements of Flow Control, Program Execution, Flow Control Statements,
Importing Modules,Ending a Program Early with sys.exit(), Functions: def Statements with Parameters, Return
Values and return Statements,The None Value, Keyword Arguments and print(), Local and Global Scope, The
global Statement, Exception Handling, A Short Program: Guess the Number
Textbook 1: Chapters 1 – 3
E
CHAPTER 1
C
1. DEFINITION : Python is a high-level, interpreted, and general-purpose programming language
N
that emphasizes simplicity and readability. It is designed to be easy to learn and use, making it an
JN
excellent choice for both beginners and experienced developers. Python supports multiple
programming paradigms, including procedural, object-oriented, and functional programming.
L,
Python is widely used in various fields such as web development, data analysis, artificial intelligence
(AI), machine learning (ML), scientific computing, automation, and more. Its extensive standard
IM
library and vast ecosystem of third-party packages make it a powerful and versatile tool for solving
diverse problems efficiently
,A
In simple terms, Python is a programming language that's like a set of instructions you give to a
M
computer to make it do something. Imagine teaching someone how to bake a cake step-by-step;
Python lets you give instructions to a computer in a similar way.
EE
Here’s why Python is great and easy to use:
AS
Simple to Read and Write: Python uses plain English-like words, so it’s easier to understand, even
for beginners. For example: print("Hello, world!"). This simply tells the computer to display "Hello,
W
world!" on the screen.
Versatile: You can use Python to do many things, like:
YA
a. Build websites
b. Analyze data
LI
c. Create games
AA
d. Control robots or devices
e. Work on Artificial Intelligence (AI) and Machine Learning (ML)
Beginner-Friendly: Python takes care of many complicated details for you, so you can focus on
solving problems rather than getting stuck on complex coding rules.
Huge Community: If you ever get stuck, there are lots of tutorials, forums, and people who can help.
Python is like a friendly tool that helps you bring your ideas to life through a computer!
Aaliya Waseem, Dept. AIML, JNNCE
1
,Introduction to Python Programming BPLCK105B
NOTE: Python was created by Guido van Rossum in 1991. He is often referred to as Python's
"Benevolent Dictator For Life" (BDFL) because he guided the development of Python for many
years.
The name "Python" was inspired by the British comedy series Monty Python's Flying Circus, not the
snake, reflecting van Rossum's preference for a fun and approachable language.
2. ENTERING EXPRESSIONS INTO THE INTERACTIVE SHELL
What is the Interactive Shell?
E
The interactive shell is a place where you can type Python code and immediately see the result. It’s
like a calculator but can do much more.
C
How to Open It?
N
JN
On Windows: Go to the Start menu, find the Python program group, and click IDLE (Python GUI).
How to Use It?
L,
At the prompt >>>, you can type commands or math expressions. For example:
>>> 2 + 2
IM
,A
4
When you press Enter, Python calculates the result and shows 4.
M
EE
What is an Expression?
● An expression is a piece of code that Python can calculate and give back a value.
AS
● For example, 2 + 2 is an expression. Python calculates it and gives the result, 4.
Values and Operators
W
● A value is just a number or a piece of data, like 2.
● An operator is something that tells Python what to do with the values. For example:
YA
○ + adds two numbers.
○ - subtracts one number from another.
LI
Single Values are Also Expressions
AA
If you type just a single value, like 2, Python will still recognize it as an expression. It simply
evaluates to itself:
>>> 2
2
Conclusion: In short: You can use the interactive shell to quickly do calculations or test Python code.
Expressions combine values and operators, and Python calculates their result for you!
Aaliya Waseem, Dept. AIML, JNNCE
2
, Introduction to Python Programming BPLCK105B
There are plenty of other operators you can use in Python expressions, too. For example, Table 1-1
lists all the math operators in Python.
E
C
N
When doing math in Python, operators (like +, -, *, /) follow specific rules, just like in regular
JN
math. These rules are called the order of operations or precedence. Python uses the same rules as
you learned in school to decide what to calculate first.
L,
Order of Operations (Precedence)
1. Exponents (**) come first
IM
Example: >>> 2 ** 3
,A
8 # (2 raised to the power of 3)
M
2. Multiplication (*), Division (/), Floor Division (//), and Modulus (%) come next
EE
These are calculated from left to right.
Examples: >>> 10 *
AS
4.0 # First, 10 * 2 = 20, then = 4.0
W
3. Addition (+) and Subtraction (-) come last
YA
These are also calculated from left to right.
Example: >>> 5 + 3 - 2
LI
6 # First, 5 + 3 = 8, then 8 - 2 = 6
AA
Overriding the Order with Parentheses
If you want to change the order Python calculates things, use parentheses. Python will always
calculate what’s inside parentheses first.
With parentheses
>>> (2 + 3) * 4
20 # First, 2 + 3 = 5, then 5 * 4 = 20
Aaliya Waseem, Dept. AIML, JNNCE
3
PYTHON MODULE 1 NOTES
Syllabus: Python Basics: Entering Expressions into the Interactive Shell, The Integer, Floating-Point, and
String Data Types, String Concatenation and Replication, Storing Values in Variables, Your First Program,
Dissecting Your Program, Flow control: Boolean Values, Comparison Operators, Boolean Operators,Mixing
Boolean and Comparison Operators, Elements of Flow Control, Program Execution, Flow Control Statements,
Importing Modules,Ending a Program Early with sys.exit(), Functions: def Statements with Parameters, Return
Values and return Statements,The None Value, Keyword Arguments and print(), Local and Global Scope, The
global Statement, Exception Handling, A Short Program: Guess the Number
Textbook 1: Chapters 1 – 3
E
CHAPTER 1
C
1. DEFINITION : Python is a high-level, interpreted, and general-purpose programming language
N
that emphasizes simplicity and readability. It is designed to be easy to learn and use, making it an
JN
excellent choice for both beginners and experienced developers. Python supports multiple
programming paradigms, including procedural, object-oriented, and functional programming.
L,
Python is widely used in various fields such as web development, data analysis, artificial intelligence
(AI), machine learning (ML), scientific computing, automation, and more. Its extensive standard
IM
library and vast ecosystem of third-party packages make it a powerful and versatile tool for solving
diverse problems efficiently
,A
In simple terms, Python is a programming language that's like a set of instructions you give to a
M
computer to make it do something. Imagine teaching someone how to bake a cake step-by-step;
Python lets you give instructions to a computer in a similar way.
EE
Here’s why Python is great and easy to use:
AS
Simple to Read and Write: Python uses plain English-like words, so it’s easier to understand, even
for beginners. For example: print("Hello, world!"). This simply tells the computer to display "Hello,
W
world!" on the screen.
Versatile: You can use Python to do many things, like:
YA
a. Build websites
b. Analyze data
LI
c. Create games
AA
d. Control robots or devices
e. Work on Artificial Intelligence (AI) and Machine Learning (ML)
Beginner-Friendly: Python takes care of many complicated details for you, so you can focus on
solving problems rather than getting stuck on complex coding rules.
Huge Community: If you ever get stuck, there are lots of tutorials, forums, and people who can help.
Python is like a friendly tool that helps you bring your ideas to life through a computer!
Aaliya Waseem, Dept. AIML, JNNCE
1
,Introduction to Python Programming BPLCK105B
NOTE: Python was created by Guido van Rossum in 1991. He is often referred to as Python's
"Benevolent Dictator For Life" (BDFL) because he guided the development of Python for many
years.
The name "Python" was inspired by the British comedy series Monty Python's Flying Circus, not the
snake, reflecting van Rossum's preference for a fun and approachable language.
2. ENTERING EXPRESSIONS INTO THE INTERACTIVE SHELL
What is the Interactive Shell?
E
The interactive shell is a place where you can type Python code and immediately see the result. It’s
like a calculator but can do much more.
C
How to Open It?
N
JN
On Windows: Go to the Start menu, find the Python program group, and click IDLE (Python GUI).
How to Use It?
L,
At the prompt >>>, you can type commands or math expressions. For example:
>>> 2 + 2
IM
,A
4
When you press Enter, Python calculates the result and shows 4.
M
EE
What is an Expression?
● An expression is a piece of code that Python can calculate and give back a value.
AS
● For example, 2 + 2 is an expression. Python calculates it and gives the result, 4.
Values and Operators
W
● A value is just a number or a piece of data, like 2.
● An operator is something that tells Python what to do with the values. For example:
YA
○ + adds two numbers.
○ - subtracts one number from another.
LI
Single Values are Also Expressions
AA
If you type just a single value, like 2, Python will still recognize it as an expression. It simply
evaluates to itself:
>>> 2
2
Conclusion: In short: You can use the interactive shell to quickly do calculations or test Python code.
Expressions combine values and operators, and Python calculates their result for you!
Aaliya Waseem, Dept. AIML, JNNCE
2
, Introduction to Python Programming BPLCK105B
There are plenty of other operators you can use in Python expressions, too. For example, Table 1-1
lists all the math operators in Python.
E
C
N
When doing math in Python, operators (like +, -, *, /) follow specific rules, just like in regular
JN
math. These rules are called the order of operations or precedence. Python uses the same rules as
you learned in school to decide what to calculate first.
L,
Order of Operations (Precedence)
1. Exponents (**) come first
IM
Example: >>> 2 ** 3
,A
8 # (2 raised to the power of 3)
M
2. Multiplication (*), Division (/), Floor Division (//), and Modulus (%) come next
EE
These are calculated from left to right.
Examples: >>> 10 *
AS
4.0 # First, 10 * 2 = 20, then = 4.0
W
3. Addition (+) and Subtraction (-) come last
YA
These are also calculated from left to right.
Example: >>> 5 + 3 - 2
LI
6 # First, 5 + 3 = 8, then 8 - 2 = 6
AA
Overriding the Order with Parentheses
If you want to change the order Python calculates things, use parentheses. Python will always
calculate what’s inside parentheses first.
With parentheses
>>> (2 + 3) * 4
20 # First, 2 + 3 = 5, then 5 * 4 = 20
Aaliya Waseem, Dept. AIML, JNNCE
3