You are on page 1of 10

PYTHON PROGRAMMING FUNDAMENTALS

1. Introduction to Python and Computer Programming


2. Command Line Interface, Python Installation and Setup
3. Interacting with Python
4. Python Operators and Data Types
5. Python String Methods and Formatting
6. Data Structures in Python
7. Python Control Flow Statements
8. Python Functions
9. Object Oriented Programming (OOP)
10.Working with External Files in Python
11.Working with Dates, Time and Calendars
12.Working with Images
13.Working with CSV and PDF
14.Errors and Exception Handling
15.Creating Basic Python Projects
16.Building Desktop GUI Apps using Python

1
Module 1: Introduction to Python and Computer Programming
Objectives of the Course
 Learn Python from scratch
 Learn how to setup a Python development environment
 Learn how to create console applications
 Learn about Python data types and casting
 Python data structures
 Python Modules and Packages
 Python String methods and Formatting
 Working with dates and time
 Python Functions
 Python Control Flow Statements
 Working with external files in Python
 Handling exception errors
 Create desktop applications using Python

Programming Language
Programs are majorly referred to as software. Software is very important to a
computer because it controls everything the computer does. All of the software that
we use to make our computers useful is created by individuals working as
programmers or software developers. A programmer, or software developer, is a
person with the training and skills necessary to design, create, and test computer
programs. Computer programming is an exciting and rewarding career. Today, you
will find programmers’ work used in business, medicine, government, law
enforcement, agriculture, academics, entertainment, and many other fields.
A programming language is a formal language which comprises of a set of
instructions that produce various kinds of output. They are used in computer
programming to implement algorithms. They are set of rules which instructs the
computer to perform specific tasks. We have the high-level programming language
and the low-level programming language.

High-level Programming Languages


High-level programming languages are languages which humans can
understand. Computers cannot understand this language unless they are compiled
or interpreted. They need an interpreter or a compiler for the computer to

2
understand what the program is meant to do. Examples of high-level programming
languages include Python, Java, C#, C++, PHP, Ruby etc.

Low-level Programming Languages


Low-level languages are languages which is understood by only machines.
Unlike the high-level language, it does not need an interpreter or a compiler. They
are closer to the computer hardware. Examples include machine and assembly
language.
A brief illustration of high-level and low-level languages is shown in figure
1.1 below:
High Level Language
 Easy for programmers to understand OO and Visual Language
 Contains English words

High-level Language
FORTRAN, C, Pascal

Low Level Language Assembly Language


 The computer·s own language
 Binary numbers (0's and 1's)
Machine Language

Hardware

Figure 1.1: A brief illustration of high-level and low-level languages


From the illustration, the nearer the language is to hardware of the machine,
the easier it is for the machine, because, it doesn’t need to be interpreted because it
is so close to the computer hardware, whereas, the further away it is from the
hardware, the easier it is for programmers to understand because they do contain
English related words. For the machine to understand it, it needs to be converted
to machine code using a compiler or an interpreter.

Differences between High-level and Low-level Languages


S/ High-level Language Low-level Language
N
1 They are easy to learn They are difficult to learn
2 They are near human languages They are far from human languages
3 Translator is required No translator is needed
4 They are slow in execution They are fast in execution

3
Compilers and Interpreters
Because the CPU understands only machine language instructions,
programs that are written in a high-level language must be translated into machine
language. Depending on the language that a program has been written in, the
programmer will use either a compiler or an interpreter to make the translation. A
compiler is a program that translates a high-level language program into a separate
machine language program. The machine language program can then be executed
any time it is needed.
A compiler is used to translate the entire source code into machine language
before the code is executed. For the computer to understand what you are trying to
do, you need the compiler to translate the code to what the machine can read and
understand. Examples of languages that are compiled before the code is executed
includes C and C++.
Interpreter performs a similar job like the compiler. The difference between
the compiler and the interpreter is that the interpreter translates or convert one
line of code at a time into machine language before the code is executed. Examples
of languages that uses an interpreter is the Python and Perl.

How does the compiler work?


Assuming you have your source code (i.e. the computer program that written
in high-level language), the compiler compiles the source code into machine code
and then it executes the code. It then passes it onto the computer memory and the
computer memory then outputs the result. The compiler compiles the entire code
into machine code before it passes the information to the CPU to display the result.
The diagram showing the illustration is shown in figure 1.2.

a=4 00001010
b=8 11000111
Compiler CPU 12
sum = a + b 10110011
Print(sum) 00101010 Result

Source code Machine code


file
Figure 1.2: The compilation process

Differences between the Compiler and Interpreter


S/ Compiler Interpreter
N
1 Transforms the entire source code Transforms line by line

4
2 Generate machine code Does not generate machine code
3 Uses more memory Less memory is used
4 Compiles once and runs anytime Source code is interpreted each time
5 More difficult to debug Easy to debug
6 Faster Slower

What is Python?
Python is a widely-used, interpreted, object-oriented, and high-level
programming language with dynamic semantics, used for general-purpose
programming. And while you may know the python as a large snake, the name of
the Python programming language comes from an old BBC television comedy
sketch series called Monty Python's Flying Circus.
At the height of its success, the Monty Python team were performing their
sketches to live audiences across the world, including at the Hollywood Bowl. Since
Monty Python is considered one of the two fundamental nutrients to a programmer
(the other being pizza), Python's creator named the language in honor of the TV
show.

5
Module 2: Command Line Interface, Python Installation and Setup
PyCharm Basic Configuration Setup on Windows
When you launch PyCharm for the first time, you get a screen shown in
figure 2.1. that ask you to import PyCharm settings. This usually happens if you
got PyCharm installed previously and you are installing maybe a different version
and you got some settings saved. Then check “Do not import settings” and click OK
to progress to the next screen.

Figure 2.1: Import PyCharm Settings Interface


On the next screen shown in figure 2.2, click on “I confirm that I have read
and accept the terms of the User Agreement” and click Continue.

Figure 2.2: Privacy Policy Interface


It will then take you to the screen on data sharing on figure 2.3, just click
“Don’t send”. It then tries to launch PyCharm.

6
Figure 2.3: Data Sharing Interface
Once it launches, you have the figure 2.4. Now, configure the basic
configurations.

Figure 2.4: Welcome Screen


Go to Configure → Settings. There you can change different things e.g.
Appearance, Editor (where you write your code). Click Ok to accept the settings.
Next is to setup the python interpreter. To do this, go to Configure → Settings →
Python Interpreter. Then you have the interface shown in figure 2.5.

7
Figure 2.5: Settings Interface
From the figure 2.6, there is no interpreter selected. To add an interpreter,
go to the settings sign beside the drop-down button and click on Add. Click on
“System Interpreter” as shown in figure 2.7 and click OK, then the package list will
be loaded. Click on OK button to update the Python interpreter. Once the
interpreter has been updated, you are back to the welcome screen.

8
Figure 2.6: Settings interface to add Python Interpreter

Figure 2.7: System Interpreter interface to add Python Interpreter


To create a new project, click on “Create New Project”. It gives you the
location as shown in figure 2.8 then change the default name “untitled” to a name
you like. Expand “Project Interpreter: New Virtualenv environment”, then check the
“Existing interpreter” radio button as shown in figure 2.9, then click Create. This
will then create the project.

Figure 2.8: Create New Project Interface

9
Figure 2.9: Adding an Interpreter to a New Python Project

10

You might also like