Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
32 views

Python Notes

Python basics
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Python Notes

Python basics
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Python Features

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:

1. Free and Open Source


Python language is freely available at the official website and you can download it from the
given download link below click on the Download Python keyword. Download Python Since
it is open-source, this means that source code is also available to the public. So you can
download it, use it as well as share it.
2. Easy to code
Python is a high-level programming language. Python is very easy to learn the language as
compared to other languages like C, C#, Javascript, Java, etc. It is very easy to code in the
Python language and anybody can learn Python basics in a few hours or days. It is also a
developer-friendly language.

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.

7. Large Community Support


Python has gained popularity over the years. Our questions are constantly answered by the
enormous StackOverflow community. These websites have already provided answers to
many questions about Python, so Python users can consult them as needed.

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.

14. Frontend and backend development


With a new project py script, you can run and write Python codes in HTML with the help of
some simple tags <py-script>, <py-env>, etc. This will help you do frontend development
work in Python like javascript. Backend is the strong forte of Python it’s extensively used for
this work cause of its frameworks like Django and Flask.

15. Allocating Memory Dynamically

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.

Q) Applications of Python Programming

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.

2. Artificial Intelligence and Machine Learning

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:

§ Pandas for Data Manipulation and Analysis.


§ NumPy and SciPy for mathematical computations.
§ Seaborn and Matplotlib for visualization.
§ Scikit learn, Tensor Flow, Keras for algorithms
3. Game Development

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.

4. Desktop GUI Development

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.

The following used Python:

§ Odoo: This is an all-in-one business management software for


enterprising purposes.
§ Tryton: general-purpose, high level, third-tier business application
6. Software Development

Python supports the development of software with its libraries and packages. It is used for
building, testing, management, and so on. For example

§ Scons help in build control


§ Buildbot and Apache are used for autonomous and continuous testing.
§ Roundup and Trac test and manage errors.
7. Educational Purposes

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:

§ Linux based Ubuntu’s Ubiquity Installer


§ Anaconda Installer of Red Hat Enterprises
9. Language Development

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.

11.Scientific and Numeric Computations

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.

15. Data Science and Data Analysis

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.

16. Audio and Video Applications

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.

17. Integration to Embedded Systems

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.

18. Building CAD Apps

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.

19. Access to Database


Python can also integrate with databases. Python has:

§ Interfaces to database management systems like MYSQL, Oracle, MS


SQL server, PostgreSQL, and so on.
Standard Database API.
§ Connection to object databases like ZODB and Durus.
20. Robotics

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.

21. Console based Apps

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

1. Explain briefly the applications of Python programming

2. Discuss the features of Python.

Q)Types of Python Operators

Here's a list of different types of Python operators that we will learn in this

tutorial.

1. Arithmetic operators

2. Assignment Operators

3. Comparison Operators/ Relational Operators

4. Logical Operators

5. Bitwise Operators
6. Special Operators

1. Arithmetic Operators

Operat Operation Exampl


or e

+ 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

addition, subtraction, multiplication, etc. For example,

sub = 10 - 5 # 5
Here, - is an arithmetic operator that subtracts two values or variables.

2. Assignment Operators

Operator Name Example

= 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

**= Exponent a **= 10 # a = a **


Assignment 10

Example:

a = 10
b=5
a += b
print(a)
# Output: 15

3. Comparison Operators or relational operators

Comparison operators compare two values/variables and return a

boolean result: True or False.

For example,

a=5
b =2
print (a > b) # True

Operator Meaning Example

== Is Equal To 3 == 5 gives us
False
!= Not Equal To 3 != 5 gives us
True

> Greater Than 3 > 5 gives us


False

< Less Than 3 < 5 gives us True

>= Greater Than or 3 >= 5 give us


Equal To False

<= Less Than or Equal 3 <= 5 gives us


To True

List of operators and their use

4. Logical Operators

Operator Example Meaning

and a and b Logical AND:


True only if both the operands are
True

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.

Example - Logical Operators

# 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

Bitwise operators act on operands as if they were strings of binary digits.

They operate bit by bit, hence the name.

For example, 2 is 10 in binary and 7 is 111.

In the table below: Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in

binary)

Operator Meaning Example

& Bitwise AND x & y = 0 (0000 0000)

| Bitwise OR x | y = 14 (0000 1110)


~ Bitwise NOT ~x = -11 (1111 0101)

^ Bitwise XOR x ^ y = 14 (0000 1110)

>> Bitwise right x >> 2 = 2 (0000 0010)


shift

<< Bitwise left shift x << 2 = 40 (0010


1000)

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

they are identical.

Operat Meaning Exampl


or e

is True if the operands are identical (refer to the x is True


same object)
is not True if the operands are not identical (do not x is not
refer to the same object) True

Example

Identity operators in Python

x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'

print(x1 is not y1) # prints False

print(x2 is y2) # prints True

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.

Example: Membership operators in Python

x = 'Hello world'

y = {1:'a', 2:'b'}
# check if 'H' is present in x string

print('H' in x) # prints True

# check if 'hello' is present in x string

print('hello' not in x) # prints True

# check if '1' key is present in y

print(1 in y) # prints True

# check if 'a' key is present in y

print('a' in y) # prints False

You might also like