Python Notes
Python Notes
Python is a dynamic, high-level, free open source, and interpreted programming language.
It supports object-oriented programming as well as procedural-oriented programming. In
Python, we don’t need to declare the type of variable because it is a dynamically typed
language. For example, x = 10 Here, x can be anything such as String, int, etc.
Features in Python
There are many features in Python, some of which are discussed below as follows:
3. Easy to Read
As you will see, learning Python is quite simple. As was already established, Python’s syntax
is really straightforward. The code block is defined by the indentations rather than by
semicolons or brackets.
4. Object-Oriented Language
One of the key features of Python is Object-Oriented programming. Python supports
object-oriented language and concepts of classes, object encapsulation, etc.
5. GUI Programming Support
Graphical User interfaces can be made using a module such as PyQt5, PyQt4, wxPython, or
Tk in Python. PyQt5 is the most popular option for creating graphical apps with Python.
6. High-Level Language
Python is a high-level language. When we write programs in Python, we do not need to
remember the system architecture, nor do we need to manage the memory.
8. Easy to Debug
Excellent information for mistake tracing. You will be able to quickly identify and correct the
majority of your program’s issues once you understand how to interpret Python’s error
traces. Simply by glancing at the code, you can determine what it is designed to perform.
9. Python is a Portable language
Python language is also a portable language. For example, if we have Python code for
Windows and if we want to run this code on other platforms such as Linux, Unix, and Mac
then we do not need to change it, we can run this code on any platform.
10. Python is an Integrated language
Python is also an Integrated language because we can easily integrate Python with other
languages like C, C++, etc.
11. Interpreted Language:
Python is an Interpreted Language because Python code is executed line by line at a time.
like other languages C, C++, Java, etc. there is no need to compile Python code this makes
it easier to debug our code. The source code of Python is converted into an immediate form
called bytecode.
12. Large Standard Library
Python has a large standard library that provides a rich set of modules and functions so you
do not have to write your own code for every single thing. There are many libraries present
in Python such as regular expressions, unit-testing, web browsers, etc.
13. Dynamically Typed Language
Python is a dynamically-typed language. That means the type (for example- int, double,
long, etc.) for a variable is decided at run time not in advance because of this feature we
don’t need to specify the type of variable.
In Python, the variable data type does not need to be specified. The memory is automatically
allocated to a variable at runtime when it is given a value. Developers do not need to write
int y = 18 if the integer value 15 is set to y. You may just type y=18.
1. Web Development
Python is widely used in web development. It makes use of simple code to build a beautiful
and functional website. It has related libraries and modules like HTTP, XML, JSON, IMAP,
POP, FTP, etc. These help in storage in databases, content management, and interfacing
with internet protocols.
It also has frameworks integrated with it like Django, Flask, Pyramid, and Bottle. In addition,
Python also comes with packages like Beautiful Soup, Twisted Python, and Feedparser.
Many AI and ML models are built using Python. Data analysts use it too. The fundamental
cause for this is the availability of many tools and libraries specific to these applications.
Some of them include:
One of the interesting applications of the Python Programming language is to build games
like egg catcher, snake game, etc.
Python comes with packages like Pygame and Pykyra to build awesome games. It facilitates
the development of 3D games with respective libraries. It is also used for scripting in many
game engines.
Famous games like Battlefield 2, World of Tanks, Toontown Online, and Civilization 4 are
also built using Python.
Its simplicity and platform independence nature make it a good choice for GUI applications.
Though Tkinter is the standard library for GUI development, there are other supporting
libraries like:
§ Wx Python
§ Kivy
§ PyQt, PySide
§ PyGUI
§ Delphi
§ GTK+
5. Enterprise/ Business Applications
Business applications are developed keeping in mind the comfort and ease of usage by the
organization. Python’s features like scalability, extensibility, and readability make it the best
choice for business applications.
Python supports the development of software with its libraries and packages. It is used for
building, testing, management, and so on. For example
Python helps beginners get introduced to the Programming environment. It is because of its
simple syntax and beginner-friendly nature. Another reason could be its scope and reach
in the development community.
8. Operating Systems Development
Many operating systems are using Python as a backbone. Generally, it is used along with C.
Some of them are as follows:
Yes! Python being one of the programming languages helps in building other languages.
These have similar syntax object models and indentation as compared to Python. Its
architecture is taken as inspiration to build:
§ Swift
§ Boo
§ Cobra
§ CoffeeScript
§ OCaml
10. Networking Programming
Besides these high-level facilities, it also supports low-level network programming. The
framework TwistedPython serves for this purpose. It also avails a socket interface for ease.
Python can also serve in doing scientific and numeric calculations. Thanks to its concerned
libraries that makes these calculations easier. Apps like Abacus and FreeCAD are built using
Python. Some of the libraries that can do these calculations are:
§ NumPy
§ SciPy
§ Pandas
§ Natural Language Toolkit
12. Web Scraping
Nowadays, Python is being widely used for web scraping purposes. We can access the
huge data over the internet using these web scraping techniques. And this data is useful in
different ways like for analysis purposes.
Some of the tools that are available in Python for scraping are:
§ BeautifulSoup
§ Python Request
§ Scrapy
§ MechanicalSoup
§ Selenium
13. Image Processing and Graphic Designing
Using Python, one can process images using libraries like Opencv and Scikit Image. These
have become popular recently for image analysis, especially in the research field.
Python is also used in animation fields. Many 2D applications like GIMP, Paint Shop Pro and
Scribus and 3D animation applications like Blender, Maya, Lightwave, and 3ds Max use
Python at the backend.
14.Text Processing
Text processing means automatic processing of electronic text. It involves tasks like
searching, formatting, generating content, and filtering based on text.
You would have heard of NLP (Natural Language Processing). If you have not heard, you
would have at least used it. The suggestions our mobile’s keyboard gives is because of NLP.
This is one of the text processing applications using Python.
Data Science and Data Analysis are two of the booming fields in the market. This involves
analysis of a huge amount of data, finding relations and doing future predictions. Python
modules like NumPy, Pandas, Matplotlib and Seaborn serve this purpose.
We can use Python to build audio and video player applications. Also these apps built using
Python show better performance compared to that of the other ones. Some examples
include CPlay and TimePlayer.
Embedded Systems and IoT are becoming popular and necessary in many places. These
use Embedded C as the backend language. Since Python is built on C Programming
language, it can communicate with these devices. One such famous device that uses Python
is Raspberry Pi.
CAD (Computer aided design) has become a common tool for engineers and architects.
They use it to creare designs, which needs high end tools to build. Python with its
user-friendly features serves for this purpose. One of the CAD applications that uses Python
is Fandango.
In robotics, Python is a popular language used by both hobbiestics and companies. One of
its uses include Raspberry Pi to build robotic models. Python is also used in companies for
robotic process automation (RPA) to build working arms and other models.
Python serves as a suitable choice to build console-based applications because of its REPL
(Read-Eval-Print Loop) principle. Also, the presence of libraries that can handle
command-line arguments adds to this.
Some advanced libraries in Python can also be used to build console-based Applications.
Important Questions
Here's a list of different types of Python operators that we will learn in this
tutorial.
1. Arithmetic operators
2. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Special Operators
1. Arithmetic Operators
+ Addition 5 + 2
= 7
- Subtraction 4 - 2
= 2
* Multiplicatio 2 * 3
n = 6
/ Division 4 / 2
= 2
// Floor 10 //
Division 3 = 3
% Modulo 5 % 2
= 1
** Power 4 ** 2
= 16
Arithmetic operators are used to perform mathematical operations like
sub = 10 - 5 # 5
Here, - is an arithmetic operator that subtracts two values or variables.
2. Assignment Operators
= Assignment a=7
Operator
+= Addition Assignment a += 1 # a = a + 1
-= Subtraction a -= 3 # a = a - 3
Assignment
*= Multiplication a *= 4 # a = a * 4
Assignment
/= Division Assignment a /= 3 # a = a / 3
%= Remainder a %= 10 # a = a %
Assignment 10
Example:
a = 10
b=5
a += b
print(a)
# Output: 15
For example,
a=5
b =2
print (a > b) # True
== Is Equal To 3 == 5 gives us
False
!= Not Equal To 3 != 5 gives us
True
4. Logical Operators
or a or b Logical OR:
True if at least one of the operands
is True
not not a Logical NOT:
True if the operand is False and
vice-versa.
# logical AND
print(True and True) # True
print(True and False) # False
# logical OR
print(True or False) # True
# logical NOT
print(not True) # False
5. Bitwise operators
In the table below: Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in
binary)
6. Special operators
Python language offers some special types of operators like the identity
operator and the membership operator. They are described below with
examples.
Identity operators
In Python, is and is not are used to check if two values are located on the
same part of the memory. Two variables that are equal does not imply that
Example
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
Here, we see that x1 and y1 are integers of the same values, so they are
equal as well as identical. Same is the case with x2 and y2 (strings).
Membership operators
In Python, in and not in are the membership operators. They are used to
test whether a value or variable is found in a sequence (string, list, tuple,
set and dictionary).
In a dictionary we can only test for presence of key, not the value.
x = 'Hello world'
y = {1:'a', 2:'b'}
# check if 'H' is present in x string