DEPARTMENT OF
COMPUTER SCIENCE.
CMP 112
[email protected]
What is Python?
Python is a widely used general-purpose, high-level
programming language developed by Guido van, Rossum.
It is an interpreted (soucrce codes are converted to object
code line-by-line), object-oriented programming language
similar to PERL, that has gained popularity because of its
clear syntax and readability. Python is said to be relatively
easy to learn and portable, meaning its statements can be
interpreted in a number of operating systems.
A notable feature of Python is its indenting of source
statements to make the code easier to read. Python offers
dynamic data type, ready-made class, and interfaces.
Programming Language;
Coded language used by programmers to write instructions
that a computer can understand to do what the
programmer (or the computer user) wants. The most basic
(called low-level) computer language is the machine
language that uses binary ('1' and '0') code which a com-
puter can run (execute) very fast without using any
translator or interpreter program, but is tedious and
complex. The high-level languages (such as Python Basic,
C, Java) are much simpler (more 'English-like') to use but
need to use another program (a compiler or an interpreter)
to convert the high-level code into the machine code.
Levels of Programming Languages;
Machine Language - Imagine them as the “native tongue”
of the computer, the language closest to the hardware
itself. Each unique computer has a unique machine
language. A machine language program is made up of a
series of binary patterns (e.g., 01011100)
Machine Language cont. - which represent simple
operations that can be accomplished by the computer (e.g.,
add two operands, move data to a memory location). Ma-
chine language programs are executable, meaning that
they can be run directly. Programming in machine language
requires memorization of the binary codes and can be diffi-
Assembly Language - They represent an effort to make
programming easier for the human. The machine language
instructions are replaced with simple pneumonic
abbreviations (e.g., ADD, MOV). Thus assembly languages
are unique to a specific computer (machine). Prior to
execution, an assembly language program requires
translation to machine language. This translation is
accomplished by a computer program known as an
Assembler. Assemblers are written for each unique
machine language.
High Level Language - High-level languages, like Python,
C,C++, JAVA etc., are more English-like and, therefore, make
it easier for programmers to “think” in the programming
language. High-level languages also require translation to
machine language before execution. This translation is
accomplished by either a compiler or an interpreter.
Compilers translate the entire source code program before
execution.(Eg: C++, Java)
Interpreters translate source code programs one line at a
time. (Eg: Python)Interpreters are more interactive than
compilers.
Data Type, Variable, Expressions;
Data Type - OR simply type is a classification of data which
tells the compiler or interpreter how the programmer
intends to use the data or what kind of data that value can
have.
Variable - Variables are the names you give to computer
memory locations which are used to store values in a
computer program, to be referenced and manipulated in a
computer program. They also provide a way of labeling data
with a descriptive name, so our programs can be
understood more clearly by the reader and ourselves. It is
helpful to think of variables as containers that hold
information. Their sole purpose is to label and store data in
memory. This data can then be used throughout your
program.
Expression - An expression in a programming language is a
combination of one or more constants, variables, operators,
and functions that the programming language interprets
(according to its particular rules of precedence and of
association) and computes to produce another value.
Examples:
result = 245.45 + 201
solution = (13 * 25) / 16
Arithematic Operators;
An arithmetic operator is a mathematical function that
takes two operands and performs a calculation on them.
They are used in common arithmetic and most computer
languages contain a set of such operators that can be used
within equations to perform a number of types of sequential
calculation.
Addition (+) Usage: 14 + 27
Subtraction (-) Usage: 15 - 92
Multiplication (*) Usage: 5 * 14
Division (/) Usage: 45 / 21
Modulus or Remainder Division (%) Usage: 200 % 2
Relational Operators;
A relational operator is a programming language construct
or operator that tests or defines some kind of relation
between two entities. These include numerical equality
(e.g., 5 == 5) and inequalities (e.g., 4 >= 3).
Examples for Practice
a = 88 a = 88
b = 103 b = 103
print(a + b) print(a * b)
c = -36 c = -36
d = 25 d = 25
print(c + d) print(c - d)
m = 80 m = 80
n=5 n=5
print(m / n) print(m ** n)
m = 80 m = 80
n=5 n=5
print(m % n) print(m == n)
NOTE: Try out these code snippets and more. Make sure
you understand the result of each operation.
If you find any part of this note difficult, note your ques-
tion(s) and direct them to me.
You can send a Mail to;
[email protected] or
[email protected]
And i will respond as soon as Possible or You can See me in
my Office.
Thank You