0% found this document useful (0 votes)
5 views41 pages

Python0 Introduction 1

The document provides an overview of algorithms, flowcharts, programming languages, and specifically Python. It explains the definitions and characteristics of algorithms and flowcharts, the types of programming languages (machine, assembly, high-level), and the role of compilers and interpreters in translating code. Additionally, it covers the history, features, and advantages of Python as a high-level, interpreted programming language.

Uploaded by

gorleyogeswari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views41 pages

Python0 Introduction 1

The document provides an overview of algorithms, flowcharts, programming languages, and specifically Python. It explains the definitions and characteristics of algorithms and flowcharts, the types of programming languages (machine, assembly, high-level), and the role of compilers and interpreters in translating code. Additionally, it covers the history, features, and advantages of Python as a high-level, interpreted programming language.

Uploaded by

gorleyogeswari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Learn

Python Programming
- Jagannath Kumar Ch
What is an Algorithm ?
• An algorithm is a finite, step-by- Example of an Algorithm (Simple Addition):
Step 1: Start
step set of well-defined Step 2: Declare variables num1, num2 and sum.
instructions used to solve a Step 3: Read values for num1, num2.
problem or perform a Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
computation to obtain a desired Step 6: Stop
output from a given input Detailed Algorithm for Simple Addition of Two Numbers:
• It takes one or more inputs, •Input:
• Number1
processes them according to • Number2
specified rules, and produces an •Process:
output. • Add Number1 and Number2
• Store the result in Sum
•Output:
• Display the value of Sum

Dept of IT - Jagannadham Ch 2
What is Flow Chart ?
• A flowchart is a graphical
representation of an algorithm.
• It uses standard symbols
connected by flow lines to show
the sequence of steps, decision-
making, and repetition (loops)
involved in solving a problem.
• Flowcharts help in designing
algorithms and understanding
the logic of a program before
writing the actual code.

Dept of IT - Jagannadham Ch 3
What is Language
• A language is a system of communication used by humans to express thoughts, ideas, and instructions.
• It may be spoken or written and consists of words, symbols, and rules arranged in a structured and conventional manner.
• Every language follows a set of rules, called grammar, which must be followed to communicate meaningfully.
• Explanation in Simple Terms
o A language helps people communicate with each other
o It uses words and symbols
o It has rules that must be followed
o Without following the rules, communication becomes difficult or unclear
• Examples of human languages include English, Telugu, and Hindi etc..
• Example 1: Human Language
o Sentence: “I am going to school.” (Grammatically correct and meaningful)
o Sentence: “Going school am I.” (Incorrect grammar, meaning is unclear)
o Explanation: Following grammatical rules is necessary for clear communication.
• Example 2: Language Used for Instructions
o When communicating with a person, we use a language they understand, such as: English ,Telugu ,Hindi and etc.
o Each language has its own rules and structure.

Dept of IT - Jagannadham Ch 4
Computer Languages
• Just like human languages, computer languages are also used for communication —but between humans and
computers.
• Computers cannot understand human languages directly
• We use programming languages (such as C, Python, or Java)
• These languages also have strict rules and syntax.
• Example : Computer Language
o print("Hello")
(Correct syntax → Computer understands)
o print Hello
(Incorrect syntax → Computer does not understand)
o Strict rules and syntax is necessary for clear understands.
• Final Conclusion
o Languages help in communication
o They follow specific rules
o Human languages communicate with people
o Computer languages communicate with machines

Dept of IT - Jagannadham Ch 5
What is Programming Language
• A programming language is a formal language used to communicate with a computer.
• It provides a structured way to write instructions (commands) and algorithms that tell a computer what
tasks to perform
• Just like spoken languages such as English or Telugu, a programming language has:
o A vocabulary (keywords), and
o A set of grammar rules (syntax)
• These rules help programmers write correct instructions that a computer can understand and execute.
• Programmers use programming languages to develop software, applications, scripts, and programs
• Types of Programming Languages
• Programming languages are broadly classified into three types:
o Machine Language
o Assembly Language
o High-Level Language
Dept of IT - Jagannadham Ch 6
Programming Languages
• Machine Language
o Machine language is the lowest-level programming language., It consists of binary digits (0s and 1s), which are directly understood by the computer’s hardware.
✓ It is machine-dependent (different computers have different machine languages).
✓ No translator is required.
✓ It is very difficult for humans to read, write, or debug.
o Example: 10110000 01100001 (This represents an instruction understood only by the machine.)
• Assembly Language
o Assembly language is a low-level programming language that uses mnemonic codes instead of binary numbers.
o Examples of mnemonics:
✓ ADD – for addition, SUB – for Subtraction, MUL – for Multiplication, MOV – for Move data and etc..
o Since computers understand only machine language, an assembler (system software) is used to translate an assembly language program into machine language.
✓ It is also machine-dependent.
✓ Easier than machine language but still difficult compared to high-level languages.
o ADD A, B - (This will add the values are stored in A and B.)
• High-Level Language
o High-level languages use English-like statements and they are easy to learn, write, and understand.
✓ They are mostly machine-independent., programs written in high-level languages must be translated into machine language before execution.
✓ A compiler or interpreter is used for translation, Programs are easy to maintain and modify.
o Common high-level languages include: BASIC, C, C++, COBOL, FORTRAN, Ada, Pascal, Python, Java
✓ Example in c : printf("Hello World");

Dept of IT - Jagannadham Ch 7
• Source Code and Object Code
o A program written in a high-level language is called Source Code.
o After translation, the machine-language version of the program is called Object Code.
• Summary of Programming Languages
Language Type Written In Translator Used Machine Dependent
Machine Language 0s and 1s None Yes
Assembly Language Mnemonics Assembler Yes
High-Level Language English-like statements Compiler / Interpreter No

Dept of IT - Jagannadham Ch 8
What is Interpreter and Compiler
• We write computer programs using high-level programming languages.
• These languages are designed for humans and use English-like words and symbols,
making them easy to read and write.
• However, a computer can understand and execute only machine language, which
consists of binary digits (0s and 1s).
• A program written in a high-level language is called source code.
• To make this source code understandable to the computer, it must be translated into
machine code.
• This translation is done using system software known as a Compiler or an
Interpreter.

Dept of IT - Jagannadham Ch 9
Compiler
• A compiler is a program that translates the entire source code into machine code at
one time.
o The translated machine code is stored as an object code / executable file.
o Once compiled, the program can run without the compiler.
o If there is an error, the compiler reports it after compiling the whole program.
o Compiled programs generally run faster.
• Example: c program

• The compiler converts the whole program into an executable file before running it.
Dept of IT - Jagannadham Ch 10
Interpreter
• An interpreter translates the source code line-by-line and executes it immediately.
o No separate executable file is created.
o If an error occurs, execution stops at that line.
o Programs are easier to test and debug.
o Interpreted programs usually run slower than compiled programs.
• Example: python program

• Each line is translated and executed immediately by the interpreter

Dept of IT - Jagannadham Ch 11
Note
• Interpreted languages do not need to be
compiled before execution.
• A program called an interpreter runs the
source code directly.
• For example, Python programs can run on
any computer that has a Python interpreter
installed.
• This allows programmers to see changes
quickly while coding.
• However, Python is generally slower than
compiled languages like C, because it does not
run machine code directly.

Dept of IT - Jagannadham Ch 12
Interpreter Compiler
Translates and executes the program one statement at Scans the entire program and translates it as a whole
a time. into machine code.
Takes less time to analyze the source code initially, Takes more time to analyze the source code, but the
but the overall execution is slower because translation execution is faster because the program is already
happens repeatedly. translated.
No intermediate object code is generated, hence are Generates intermediate object code and requires
memory efficient. linking, hence needs more memory.

Stops execution as soon as the first error is Reports all errors only after scanning the entire
encountered, which makes debugging easier. program, making debugging comparatively difficult..

Examples of languages that commonly use Examples of languages that commonly use compilers: C,
interpreters: Python, Ruby, JavaScript. C++..

Dept of IT - Jagannadham Ch 13
Key Differences Between Compiler and Interpreter
Compiler Interpreter
Translates the entire program at once Translates the program line by line
Produces an executable file Does not produce an executable file
Errors are reported after compilation Errors are reported line by line
Execution is faster Execution is slower
Example: C, C++ Example: Python, JavaScript

Error: Division by zero Hello


Error: Division by zero

It checks the entire program first and reports It executes line by line.
errors before execution. Once the error occurs, execution stops, and
The program does not run until all errors are fixed "World" is never printed
Dept of IT - Jagannadham Ch 14
What is Python
• Python is an interpreted, high-level, object-oriented programming language with
dynamic semantics.
• Python’s simple and easy-to-learn syntax emphasizes readability, which reduces the cost
of program development and maintenance.
• Python supports modules and packages, which promote program modularity and code
reuse.
• Python’s high-level built-in data structures, along with dynamic typing and dynamic
binding, make it suitable for Rapid Application Development (RAD). It is also widely
used as a scripting or glue language to connect different software components.
• Python is an open-source programming language that is designed to be easy to read,
write, and understand.
• Finally, Python is a powerful, open-source, high-level programming language known for
its simplicity, readability, and wide range of applications, including web development,
data science, automation, and artificial intelligence.

Dept of IT - Jagannadham Ch 15
History of Python
• Python is a high-level programming language created by Guido van Rossum.
• The development of Python began in the late 1980s, and its first public release was made in February 1991.
• Python was mainly influenced by the following programming languages:
o ABC
o Modula-3
o C
• Why was Python created?
o In the late 1980s, Guido van Rossum was working at CWI (Centrum Wiskunde & Informatica), Netherlands, on the Amoeba
distributed operating system
o He wanted a programming language that:
✓ Had simple and readable syntax like ABC
✓ Was interpreted
✓ Could interact with the Amoeba operating system
✓ Was extensible and practical for real-world programming
o Since ABC was not flexible enough for system-level tasks, Guido decided to design a new language.
This new language later became known as Python.
o Python also adopted useful ideas from languages such as C, C++, Perl, and Lisp.

Dept of IT - Jagannadham Ch 16
• Why was the Name “Python” Chosen?
o Python was not named after a snake.
o Guido van Rossum was a fan of the British comedy television show “Monty Python’s Flying
Circus”, which aired in the 1970s.
o He chose the name Python because it was short, unique, and fun, and it reflected the
language’s goal of being simple and enjoyable to use
• Note : Python 2.x is no longer supported, and Python 3.x is the recommended and actively used
version today.
• Release Dates of Important Python Versions
Version Description Release Date
Python 1.0 First official version January 1994
Python 1.6 Last release of Python 1.x September 5, 2000
Python 2.0 Introduced list comprehensions October 16, 2000
Python 2.7 Last release of Python 2.x July 3, 2010
Python 3.0 Major redesign, removed redundant features December 3, 2008
Python 3.x Current and actively developed series Ongoing

Dept of IT - Jagannadham Ch 17
• Why was the Name “Python” Chosen?
o Python was not named after a snake.
o Guido van Rossum was a fan of the British comedy television show “Monty Python’s Flying
Circus”, which aired in the 1970s.
o He chose the name Python because it was short, unique, and fun, and it reflected the
language’s goal of being simple and enjoyable to use
• Note : Python 2.x is no longer supported, and Python 3.x is the recommended and actively used
version today.
• Release Dates of Important Python Versions
Version Description Release Date
Python 1.0 First official version January 1994
Python 1.6 Last release of Python 1.x September 5, 2000
Python 2.0 Introduced list comprehensions October 16, 2000
Python 2.7 Last release of Python 2.x July 3, 2010
Python 3.0 Major redesign, removed redundant features December 3, 2008
Python 3.x Current and actively developed series Ongoing

Dept of IT - Jagannadham Ch 18
Simple Illustrative Examples
• Example 1: Simplicity of Python (Inspired by ABC)
print("Hello, World!")
• Example 2: Improvement in Python 3 (Compared to Python 2)
o Python 2 style (old):
print "Hello"
o Python 3 style (current):
print("Hello")

• Example 3: List Comprehension (Introduced in Python 2.0)


squares = [x*x for x in range(1, 6)]
print(squares)

Dept of IT - Jagannadham Ch 19
Features of Python Programming
• Python provides many powerful features that make it one of the most popular programming languages
today.
• Simple and Easy to Learn
o Python has a simple, clear, and elegant syntax, which makes it easier to read, write, and understand compared to
languages such as C, C++, Java, and C#.
o Example: C Python

• Free and Open Source


o Python is free and open source, which means:
✓ You can download and use it without paying any license fee.
✓ You can study, modify, and distribute its source code.
o Example: Python can be freely downloaded and used for personal, academic, and commercial projects

Dept of IT - Jagannadham Ch 20
• Portable (Platform Independent)
o Python programs can run on multiple platforms without any modification.
o Supported platforms include: Windows, macOS, Linux
o Example:
✓ A Python program written on Windows can run on Linux or macOS without changing the code.
• Extensible and Embeddable
o Python allows integration with other programming languages like C and C++ for performance-
critical tasks
✓ Extensible: Python code can call C/C++ code.
✓ Embeddable: Python can be embedded inside other applications.
o Example:
✓ High-performance modules in games or scientific applications can be written in C and used in Python

Dept of IT - Jagannadham Ch 21
• High-Level and Interpreted Language
o Python is a high-level language, so the programmer does not need to manage:
✓ Memory allocation , Garbage collection, Hardware-level operations
o Python is also an interpreted language, meaning the code is executed line by line.
o Example:
a = 10
b = 20
print(a + b)

• Large Standard Library


o Python provides a large standard library that helps programmers perform common tasks easily
o Some common libraries:
✓ math – mathematical operations
✓ os – operating system interaction
✓ sys – system-specific parameters
o Example:
import math
print([Link](16))

Dept of IT - Jagannadham Ch 22
• Object-Oriented Programming Support
o Python supports Object-Oriented Programming (OOP) concepts such as:
✓ Classes
✓ Objects
✓ Inheritance
✓ Polymorphism
o OOP helps in solving complex problems by breaking them into smaller, manageable parts.
o Example:
class Student:
name = “Jagannath"
print([Link])

• Dynamic Typing
o In Python, data types are determined at runtime, so you do not need to declare them explicitly.
o Example:
x = 10
x = "Python"
print(x)

Dept of IT - Jagannadham Ch 23
• Built-in Data Structures
o Python provides several built-in data structures such as:
✓ List, Tuple, Dictionary, Set
o Example:
numbers = [1, 2, 3, 4]
print(numbers)

• Modules and Packages


o Python supports modules and packages, which allow code reuse and better program organization.
o Example:
import math
import MySQLdb
print([Link](25))

• Open-Source Language
o Python is open source and maintained by a global community of developers..
o Example:
✓ Python can be freely used in education, research, web development, data science, and artificial intelligence

Dept of IT - Jagannadham Ch 24
Applications of Python

Dept of IT - Jagannadham Ch 25
• Web Applications
o Python can be used to create scalable and dynamic web applications using various web
frameworks and Content Management Systems (CMS).
o Some popular Python-based platforms for web development are:
✓ Django, Flask, Pyramid, Plone, Django, CMS
o Several well-known websites use Python for their backend development, such as Instagram,
Reddit, Mozilla, and PBS.
o Example:
✓ Using the Flask framework, a simple web application that displays a message can be created in a few lines
of code

26
Dept of IT - Jagannadham Ch
• Scientific and Numeric Computing
o Python provides a wide range of libraries for scientific, mathematical, and numerical
computations.
o Some commonly used libraries include:
✓ NumPy – for numerical operations and array handling
✓ SciPy – for scientific and engineering computations
o There are also domain-specific libraries, such as:
✓ EarthPy – for earth and environmental science
✓ AstroPy – for astronomy
o Python is also extensively used in machine learning, data mining, artificial intelligence, and
deep learning.
o Example: Using NumPy to calculate the average of numbers

27
Dept of IT - Jagannadham Ch
• Creating Software Prototypes
o Python is an interpreted language, so it is generally slower than compiled languages like C or
C++. Therefore, it may not be suitable for applications where high performance and limited
resources are critical.

o However, Python is an excellent language for rapid prototyping because it allows developers to
quickly test ideas and designs.

o For example, Pygame, a Python library, can be used to create a prototype of a game. Once the
prototype is successful, the final version can be developed using a faster language such as C++

o Example: A simple Pygame window for testing a game idea:

28
Dept of IT - Jagannadham Ch
• Python as a Teaching Language
o Python is widely used by schools, colleges, and training institutions to teach programming to
beginners and children

o It is a powerful language with many features, yet it is easy to learn due to its simple and readable
syntax.

o Python programs are often shorter and closer to everyday English, which helps learners focus
on logic rather than complex syntax.

o Example:
✓ A simple Python program to display a message:

29
Dept of IT - Jagannadham Ch
Python is an ocean of opportunities!!
• Python is a widely used and powerful high-level programming language. Due to its
simple syntax and readability
• Python has become one of the most popular programming languages in the world.
• It is used by individuals, educational institutions, and major organizations across
various fields.
• Many leading technology companies and organizations use Python extensively. These are
often referred to as the key players or major users of Python.
• Some well-known organizations that use Python include:
o Google – for system automation and web development
o NASA – for scientific computations and data analysis
o Netflix – for data analysis and recommendation systems
o Instagram – for backend web development

Dept of IT - Jagannadham Ch 30
Why is Python a Very Easy-to-Read Language?
• Python is considered a very easy-to-read programming language because it uses indentation
(whitespace) to define the structure of the code.
• This means that spaces or tabs are used to organize blocks of code, such as loops and
conditional statements.
• Unlike languages such as C or C++, Python does not use curly braces { } to group
statements and does not require semicolons ; at the end of each line.
• Because of this, Python programs look clean, simple, and close to everyday English,
which makes them easy to read and understand.
• Key Reasons Python Is Easy to Read
o Indentation defines code blocks
o No curly braces { }
o No semicolons ; at the end of lines
o Simple and syntax like English

Dept of IT - Jagannadham Ch 31
• Python Code (Easy to Read)

o Explanation:
✓ The indented line shows that it belongs to the if statement
✓ No { } or ; are needed
✓ The structure is clear just by looking at the spaces
o Similar Code in C (For Comparison)

✓ Curly braces { } are required.


✓ Semicolon ; is mandatory.
✓ The code structure is less visually clear compared to Python
Dept of IT - Jagannadham Ch 32
5 Reasons to Choose Python as the First Programming Language
• Simple and Elegant (Graceful) Syntax
o Python has a simple, clean, and natural-looking syntax, which makes programs easy to understand and
write.
o The syntax of Python is very close to the English language.
o Because of this, even a beginner with no prior programming experience can easily understand Python code.
o Example Code:

o From the code, it is easy to understand that:


✓ Two numbers (a and b) are added
✓ The result is stored in sum
✓ The result is printed
o Even without programming knowledge, the purpose of the program is clear.

Dept of IT - Jagannadham Ch 33
• Not Overly Strict
o Python is a flexible language and is not very strict compared to other programming languages.
o You do not need to declare the data type of a variable.
o There is no need to use a semicolon (;) at the end of statements.
o Example Code:

o Python automatically identifies the data type of the variable, making coding easier for beginners
• Enforces Good Programming Practices
• Python forces programmers to use proper indentation, which improves code readability and structure.
• Good indentation helps beginners learn clean and organized coding habits from the beginning

• The indented line clearly shows that it belongs to the if statement

Dept of IT - Jagannadham Ch 34
• Expressive Language
o Python is a very expressive language, which means more work can be done using fewer
lines of code.
o With Python, complex applications such as games, web applications, and graphical programs
can be developed using relatively less code.
o Example:
✓ A simple Tic-Tac-Toe game with a graphical interface can be created in less than
500 lines of code using Python libraries.
o This shows how powerful and expressive Python is.
• Great Community and Support
• Python has a large and active community of programmers around the world
• There are many online forums, discussion groups, and tutorials.
• Beginners can easily get help when they face problems.
• This strong community support makes learning Python easier and more enjoyable.

35
Dept of IT - Jagannadham Ch
Run Python on Your Operating Systems
• Installing Python Using Ubuntu Package Manager (Recommended) – Method1
o Step 1: Update the Package List
o Open the Terminal and type:
sudo apt update
o Step 2: Install Python 3
sudo apt install python3
o Step 3: Verify the Installation
python3 --version
o Output Example:
Python 3.x.x

Dept of IT - Jagannadham Ch 36
• Installing and Running Python on Linux (Ubuntu) – Method2
o Python can be installed and run easily on the Linux (Ubuntu) operating system by following the steps given below.
o Install Required Dependencies :
✓ Before installing Python from source code, some supporting packages (dependencies) must be installed.
✓ Open the terminal and type the following commands:
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libsqlite3-dev
$ sudo apt-get install libbz2-dev
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev tk-dev libgdbm-dev libc6-dev
✓ These libraries are required for building and running Python properly on Ubuntu.
o Download Python Source Code
✓ Visit the official Python website: [Link]
✓ Download the required Python 3 source package (e.g., [Link])
o Extract the Downloaded File –
✓ Navigate to the download directory and extract the file:
tar -xvf [Link] ( Note : Replace 3.x.x with the actual version number.)

37
Dept of IT - Jagannadham Ch
o Compile and Install Python
ubuntu@Jagannath~$ cd Python-3.x.x
ubuntu@Jagannath~/Python-3.x.x$./configure
ubuntu@Jagannath~/Python-3.x.x$ make
ubuntu@Jagannath~/Python-3.x.x$ sudo make install
o Running Python in the Terminal
✓ To start the Python interpreter, type:
ubuntu@Jagannath~$ python3
✓ You will enter the Python interactive shell, and the prompt changes to:
Python 3.x.x (default, ...)
[GCC ...] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
✓ Error case (if Python 3 is not installed) -
Command 'python3' not found, but can be installed with:
sudo apt install python3
✓ Python code in python shell
>>> print( “ Hello World!”)
>>> Hello World!

38
Dept of IT - Jagannadham Ch
Install and Run Python in Windows
• Python can be installed and run on Windows using the official installer and its built-in IDE called IDLE
• Download Python
o Go to the official Python website: [Link]
o Click Download Python 3.x (use the latest stable version instead of older versions like 3.4.3).
• Install Python
o Once the installer is downloaded, double-click the file.
o In the setup window:
✓ Check “Add Python to PATH” (important for running Python from the command line).
✓ Click Install Now and follow the instructions.
o Note: Installing Python automatically installs IDLE, a simple graphical interface for writing and running Python programs.
• Run Python using IDLE
o Open IDLE from the Start menu.
o You will see the Python prompt:
Python 3.14.2 (tags/v3.14.2:df79316, Dec 5 2025, 17:18:21) [MSC v.1944 64 bit (AMD64)] on win32
Enter "help" below or click "Help" above for more information.
>>>

o This indicates that Python is ready to accept commands in Immediate Mode


o Hello World in IDLE
>>> print( “ Hello World!”)
>>> Hello World!

Dept of IT - Jagannadham Ch 39
• Create and Run a Python File (Script Mode)
o In IDLE, go to File > New Window (Shortcut: Ctrl+N).
o Write the following Python code in the new window:

o Save the file with a .py extension, for example: [Link] (Shortcut: Ctrl+S).
o Run the program: Run > Run Module (Shortcut: F5).
>>> Hello World!

o Congratulations! You have successfully run your first Python program in Windows.

Dept of IT - Jagannadham Ch 40
Types of Python Modes in Windows
• Python can be executed in three main modes:
• Immediate Mode (Interactive Mode)
o Run Python directly in the command prompt or IDLE prompt (>>>).
o You can type Python expressions and get instant output.
• Script Mode
o Used to execute a Python program written in a file (script).
o Scripts are saved with the .py extension.
o Can be executed from command prompt or IDLE.
o Command Prompt Execution:
• Integrated Development Environment (IDE)
• Any text editor or IDE can be used to write Python scripts, e.g.
✓ IDLE (default),
✓ Notepad,
✓ Sublime Text,
✓ VS Code
• IDEs often provide extra features like syntax highlighting, debugging, and auto-completion

Dept of IT - Jagannadham Ch 41

You might also like