COMPUTER
PROGRAMMING 2
ELEZEAR R. REPIL
More about Python
• Python is a high-level, general-purpose and a very popular
programming language.
• Python programming language (latest Python 3) is being used in
web development, Machine Learning applications, along with all
cutting edge technology in Software Industry.
• Python Programming Language is very well suited for Beginners,
also for experienced programmers with other programming
languages like C++ and Java.
More about Python
The name Python was selected from "Monty Python's Flying Circus" which
was a British sketch comedy series created by the comedy group Monty
Python and broadcast by the BBC from 1969 to 1974
Python was created in the early 1990s by Guido van Rossum at the National
Research Institute for Mathematics and Computer Science in Netherlands.
Centrum Wiskunde en Informatica
(CWI) is the national research institute A lambda function can take any
for mathematics and computer number of arguments, but can
science in the Netherlands only have one expression.
Python Features
Readability and Simplicity:
• Python emphasizes code readability and a clean, easy-to-understand syntax.
• The use of indentation for block structure makes code more readable.
Expressive Language:
• Python allows developers to express ideas in fewer lines of code compared to
languages like C++ or Java.
Interpreted and Interactive:
• Python is an interpreted language, which means code can be executed line by line.
• Interactive mode allows testing code snippets and exploring features interactively.
Python Features
Cross-platform: Puysthwoinht ism
• Python is compatible with various operating systems, including Windows, macOS, and
maonrye
Linux.
Large Standard Library:
• Python comes with a comprehensive standard library that includes modules and
packages for various tasks.
Dynamically Typed:
• Python is dynamically typed, enabling flexibility and ease of use. Variables don't need
explicit type declarations.
Object-Oriented:
• Python supports object-oriented programming (OOP) principles, facilitating code
organization and reuse.
Python Features
Extensible and Embeddable: Puysthwoinht ism
• Python can be extended with C/C++ code, allowing integration with other languages.
aonrye
• It can be embedded into applications to provide scriptingmcapabilities.
Community Support:
• Python has a large and active community, contributing to a wealth of resources,
libraries, and frameworks.
Exception Handling:
• Python has a robust and easy-to-use exception handling mechanism for managing
errors.
Dynamic Memory Management:
• Python has automatic memory management, handled by a garbage collector,
reducing the burden on developers.
Facts about python
1. Python is currently the most widely used multi-purpose, high-level
programming language.
2.Python allows programming in Object-Oriented and Procedural
paradigms.
3.Python language is being used by almost all tech-giant companies like –
Google, Amazon, Facebook, Instagram, Dropbox, Uber, Mozilla, Spotify,
Quora, and many more. .
Facts about python
4. The biggest strength of Python is huge collection of standard library which
can be used for the following:
1. Machine Learning
2. GUI Applications (like Kivy, Tkinter, PyQt etc. )
3. Web frameworks like Django (used by YouTube, Instagram, Dropbox)
4. Image processing (like OpenCV(Open Source Computer Vision Library)
and Pillow)
5. Web scraping (like Scrapy, BeautifulSoup, Selenium)
6. Test frameworks
7. Multimedia
8. Scientific computing and many more
A virtual machine is a computer file,
typically called an image, that behaves
like an actual computer.
Difference between Compiler and Interpreter
• Compiler transforms code written in a high-level programming language
into the machine code at once before the program runs, whereas an
Interpreter converts each high-level program statement, one by one, into
the machine code, during program run.
• Compiled code runs faster, while interpreted code runs slower.
• Compiler takes an entire program, whereas the Interpreter takes a single
line of code.
• Compiler displays all errors after compilation, on the other hand, the
Interpreter displays errors of each line one by one.
• Compiler is based on translation linking-loading model, whereas the
Interpreter is based on Interpretation Method.
Python Structure
• Python programs are
composed of modules
• Modules contain
statements
• Statements contain
expressions
• Expressions create
and
process objects
Comments in Python
• Comments in Python is the inclusion of short descriptions along
with the code to increase its readability and explaining the code to
others .
• Comments in Python are identified with a hash symbol, #, and
extend to the end of the line. Hash characters in a string are not
considered comments, however.
Indentation in Python
• Indentation is a very important concept of Python because
without properly indenting the Python code, you will end up
seeing IndentationError and the code will not get compiled.
• Python indentation refers to adding white space
before a
statement to a particular block of code.
• In another word, all the statements with the same space to the
right, belong to the same code block.
Indentation in Python
Python Coding Style
Use 4 spaces per indentation.
Python Coding Style
Maximum line
length : 79
characters
which help
users with a
small display.
Python Coding Style
Use blank lines to separate
top-level function and class
definitions and single blank
line to separate methods
definitions inside a class and
larger blocks of code inside
functions. Use spaces around
expressions and statements.
Python Coding Style
En
d