Department of Computer Science and Engineering: Programming in Python
Department of Computer Science and Engineering: Programming in Python
Programming in Python
Open Elective VII Semester ME
(9th Sep – 10th Jan 2024 )
Introduction,
Data, Expressions,
Statements
Introduction
Creativity and motivation:
When you first start, you will be both the programmer and the end user of your programs. As you gain skill as a
programmer and programming feels more creative to you, your thoughts may turn toward developing programs for
others.
The CPU understands a language we call machine language. Machine language is very simple and frankly very
tiresome to write because it is represented all in zeros and ones:
Since machine language is tied to the computer hardware, machine language is not portable across different
types of hardware.
Programs written in high-level languages can be moved between different computers by using a different
interpreter on the new machine or recompiling the code to create a machine language version of the program for
the new machine.
These programming language translators fall into two general categories: (1) interpreters and (2) compilers.
Terminology: Interpreter and compiler
An interpreter reads the source code of the program as written by the programmer, parses the source code, and
interprets the instructions one line at a time.
Python is an interpreter where we can type a line of Python (a sentence) and Python processes it immediately
and is ready for us to type another line of Python.
Some of the lines of Python tell that you want it to remember some value for later. We need to pick a name for
that value to be remembered and we can use that symbolic name to retrieve the value later. We use the term
variable to refer to the labels we use to refer to this stored data.
A compiler needs to be handed the entire program in a file, and then it runs a
process to translate the high-level source code into machine language and then
the compiler puts the resulting machine language into a file for later execution.
Terminology: Interpreter and compiler
If you have a Windows system, often these executable machine language programs have a suffix of “.exe” or
“.dll” which stand for “executable” and “dynamic link library” respectively.
In Linux and Macintosh, there is no suffix (or extension) that uniquely marks a file as executable. If you were to
open an executable file in a text editor, it would look completely crazy and be unreadable:
The Python interpreter is a program that reads and executes Python code. Depending on your environment, you
might start the interpreter by clicking on an icon, or by typing python on a command line. When it starts, you
should see output like this:
Running Python Program
Running Python Program
Because we all grow up speaking natural languages, it is sometimes hard to adjust to formal languages. The
difference between formal and natural language is like the difference between poetry and prose, but more so:
Learning to debug can be frustrating, but it is a valuable skill that is useful for many
activities beyond programming.