Python Programming
A Concise Guide
June 2025
Introduction
Python is one of the most popular programming language in
recent time. It is a high-level programming language that is
widely used in data analysis, web development and scientific
computing, among others. It is known for its simplicity.
Python is Interpreted: This means that it is processed at
runtime by the interpreter and you do not need to compile
your program before executing it.
Python is also interactive. This means that you can
actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
Features of Python
Easy-to-learn: Python has relatively few keywords,
simple structure, and a clearly defined syntax.
Easy-to-read: Python code is much more clearly
defined and visible to the eyes.
Easy-to-maintain: Python's success is that its
source code is fairly easy-to-maintain.
A broad standard library: One of Python's greatest
strengths is the bulk of the library is very portable
and cross-platform compatible on UNIX, Windows,
and Macintosh.
Features of Python Cont’d
Portable: Python can run on a wide variety of
hardware platforms and has the same interface on
all platforms.
Extendable: You can add low-level modules to the
Python interpreter. These modules enable
programmers to add to or customize their tools to
be more efficient.
Scalable: Python provides a better structure and
support for large programs.
Reserved Words:
Keywords contain lowercase letters only.
and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield
Python Development Tools
Python IDEs and Editors enables you to code, edit, execute or
interpret python source code and display output on screen.
Some commonly used IDEs and Editors are highlighted below,
including links to download them.
1. Visual Studio (VSCode) (https://code.visualstudio.com/download)
2. PyDev (for Eclipse) (www.pydev.org)
3. Pycharm (www.jetbrains.com/pycharm/download)
4. Sublime Text (www.sublimetext.com/download)
5. Spyder (www.spyder-ide.org)
6. Jupyter Notebook (https://jupyter.org)
7. Anaconda (www.anaconda.com)
Installing Python
Launch or visit www.python.org
Choose the version
Download the executable file
Run executable file
In the setup window, you will the option “Add python
to PATH”. This will you to run Python code from the
command line.
Click the “Install Now” button and follow the
installation guide.
Verify that python is installed
File Naming Convention
Python files normally ends with the suffix .py
Operator, Expression and Statements
An operator: It is a symbol or sign that performs a specific
action in an expression.
An Expression: It is a combination operators and operand or
value.
Statement: A statement is a set of instruction in the computer
program that performs specific action in a program. A
statement could be executable. Non-executable statements
are statements that are ignored by the interpreter during
program execution. An example of a non-executable
statement is a comment.
Operator Precedence: This is an order that specifies how an
operator is evaluated in an expression.
Common Operators
Operators are special symbols Logical Operators
used in expressions. They are
as follows: and: This operator
+ (Addition) returns true if both
- (Subtraction) operands are true.
* (Multiplication) or: Returns true if either
/ (Division) of the operand is true
< (Less than)
not: Returns true if the
> (Greater than)
operand is false and
== (equal to)
vice versa.
Python Arithmetic Operators
Operator Description Example
+ Addition - Adds values on either side of the a+b (2+3=5)
operator
- Subtraction - Subtracts right hand operand a–b (7-4=3)
from left hand operand
* Multiplication - Multiplies values on either x*y (3*5=15)
side of the operator
/ Division - Divides left hand operand by right b/a (6/2=3)
hand operand
% Modulus - Divides left hand operand by b%a (10%3=1)
right hand operand and returns remainder
** Exponentiation - Performs exponential x**y (3**2=9)
(power) calculation on operators
// Floor Division - The division of operands x//y (9//2=4)
where the result is the quotient in which
the digits after the decimal point are
removed.
Python Assignment Operators
Operator Description Example
= Simple assignment operator, Assigns values from right side c = a + b will assigne
operands to left side operand value of a + b into c
+= Add AND assignment operator, It adds right operand to the c += a is equivalent
left operand and assign the result to left operand to c = c + a
-= Subtract AND assignment operator, It subtracts right c -= a is equivalent
operand from the left operand and assign the result to left to c = c - a
operand
*= Multiply AND assignment operator, It multiplies right c *= a is equivalent
operand with the left operand and assign the result to left to c = c * a
operand
/= Divide AND assignment operator, It divides left operand c /= a is equivalent
with the right operand and assign the result to left operand to c = c / a
%= Modulus AND assignment operator, It takes modulus using c %= a is equivalent
two operands and assign the result to left operand to c = c % a
**= Exponent AND assignment operator, Performs exponential c **= a is equivalent
(power) calculation on operators and assign value to the left to c = c ** a
operand
//= Floor Division and assigns a value, Performs floor division on c //= a is equivalent
operators and assign value to the left operand to c = c // a
Operators Precedence
Operator Description
** Exponentiation (raise to the power)
* / % // Multiply, divide, modulo and floor division
+- Addition and subtraction
>> << Right and left bitwise shift
& Bitwise 'AND'
^| Bitwise exclusive `OR' and regular `OR'
<= < > >= Comparison operators
<> == != Equality operators
= %= /= //= -= += Assignment operators
*= **=
is not Identity operators
in not in Membership operators
not or and Logical operators
Comments in Python
A hash sign (#) that is not inside a string literal begins a
comment. All characters after the # and up to the
physical end of line are part of the comment, and the
Python interpreter ignores them.
There are two types of Comments in Python
Single Line - To write a single line comment, simply put
the hash sign (#) before your comment as long as it is
on same line
Example - print ("This is my first program") # This is a
single line comment.
Comments in Python
Multiple Line Comments: Begin each line with a hash sign
(repeatedly) or simply wrap comments enclosed in a triple quote.
Example of Multi-line Comments
"""Program to calculate the area of a rectangle
It includes a formatted result to enhance readability and makes
understanding easy but you can also initialize each line with the
hash sign (#)
"""
L=12
W=10
area=L*W
print("The Area is:",area)
EXERCISES
Exercise 1
Write a python #Program to add two numbers
program to calculate x=12
the sum of the y=20
following numbers:
Sum=x+y
12, 20
print('The Sum is:', Sum)
Exercise 2
Write a python a=23
program to calculate b=25
Average of the C=30
following numbers: Sum=a+b+c
23, 25, 30. Average=sum/3
print(Average)
Class Exercise 3
Write a python # Program to display your name and department
code to display name="Mr. Barima Precious"
your name and department=“Computer Science"
department . print("my name is:",name)
print("My Department is:",department)