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

Python Notes

Python is a high-level, object-oriented programming language known for its simplicity and versatility, making it suitable for various applications such as web development, data science, and artificial intelligence. It features an easy-to-learn syntax, extensive libraries, and a strong community, which enhances productivity and career opportunities for developers. Python supports multiple data types and structures, including lists, tuples, and strings, and is widely used in fields like machine learning, scientific computing, and automation.

Uploaded by

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

Python Notes

Python is a high-level, object-oriented programming language known for its simplicity and versatility, making it suitable for various applications such as web development, data science, and artificial intelligence. It features an easy-to-learn syntax, extensive libraries, and a strong community, which enhances productivity and career opportunities for developers. Python supports multiple data types and structures, including lists, tuples, and strings, and is widely used in fields like machine learning, scientific computing, and automation.

Uploaded by

rashidgada1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Python

Python is a simple, general purpose, high level, and object-oriented


programming language. Python is an interpreted scripting language also. Guido
Van Rossum is known as the founder of Python programming.
Python is a general-purpose, dynamic, high-level, and interpreted programming
language. It supports Object Oriented programming approach to develop
applications. It is simple and easy to learn and provides lots of high-level data
structures.
Python has many web-based assets, open-source projects, and a vibrant
community. Learning the language, working together on projects, and
contributing to the Python ecosystem are all made very easy for developers.

Features of Python

o Easy to use and Learn: Python has a simple and easy-to-understand


syntax, unlike traditional languages like C, C++, Java, etc., making it easy for
beginners to learn.
o Expressive Language: It allows programmers to express complex concepts
in just a few lines of code or reduces Developer's Time.
o Interpreted Language: Python does not require compilation, allowing rapid
development and testing. It uses Interpreter instead of Compiler.
o Object-Oriented Language: It supports object-oriented programming,
making writing reusable and modular code easy.
o Open Source Language: Python is open source and free to use, distribute
and modify.
o Extensible: Python can be extended with modules written in C, C++, or
other languages.
o Learn Standard Library: Python's standard library contains many modules
and functions that can be used for various tasks, such as string manipulation,
web programming, and more.
o GUI Programming Support: Python provides several GUI frameworks, such
as Tkinter and PyQt, allowing developers to create desktop applications
easily.
o Integrated: Python can easily integrate with other languages and
technologies, such as C/C++, Java, and . NET.
o Embeddable: Python code can be embedded into other applications as a
scripting language.
o Dynamic Memory Allocation: Python automatically manages memory
allocation, making it easier for developers to write complex programs without
worrying about memory management.
o Wide Range of Libraries and Frameworks: Python has a vast collection of
libraries and frameworks, such as NumPy, Pandas, Django, and Flask, that can
be used to solve a wide range of problems.
o Versatility: Python is a universal language in various domains such as web
development, machine learning, data analysis, scientific computing, and
more.
o Large Community: Python has a vast and active community of developers
contributing to its development and offering support. This makes it easy for
beginners to get help and learn from experienced developers.
o Career Opportunities: Python is a highly popular language in the job
market. Learning Python can open up several career opportunities in data
science, artificial intelligence, web development, and more.
o High Demand: With the growing demand for automation and digital
transformation, the need for Python developers is rising. Many industries seek
skilled Python developers to help build their digital infrastructure.
o Increased Productivity: Python has a simple syntax and powerful libraries
that can help developers write code faster and more efficiently. This can
increase productivity and save time for developers and organizations.
o Big Data and Machine Learning: Python has become the go-to language
for big data and machine learning. Python has become popular among data
scientists and machine learning engineers with libraries like NumPy, Pandas,
Scikit-learn, TensorFlow, and more.

Python used

Python is a general-purpose, popular programming language, and it is used in


almost every technical field. The various areas of Python use are given below.

o Data Science: Data Science is a vast field, and Python is an important


language for this field because of its simplicity, ease of use, and
availability of powerful data analysis and visualization libraries like NumPy,
Pandas, and Matplotlib.
o Desktop Applications: PyQt and Tkinter are useful libraries that can be
used in GUI - Graphical User Interface-based Desktop Applications. There
are better languages for this field, but it can be used with other languages
for making Applications.
o Console-based Applications: Python is also commonly used to create
command-line or console-based applications because of its ease of use
and support for advanced features such as input/output redirection and
piping.
o Mobile Applications: While Python is not commonly used for creating
mobile applications, it can still be combined with frameworks like Kivy or
BeeWare to create cross-platform mobile applications.
o Software Development: Python is considered one of the best software-
making languages. Python is easily compatible with both from Small Scale
to Large Scale software.
o Artificial Intelligence: AI is an emerging Technology, and Python is a
perfect language for artificial intelligence and machine learning because of
the availability of powerful libraries such as TensorFlow, Keras, and
PyTorch.
o Web Applications: Python is commonly used in web development on the
backend with frameworks like Django and Flask and on the front end with
tools like JavaScript and HTML.
o Enterprise Applications: Python can be used to develop large-scale
enterprise applications with features such as distributed computing,
networking, and parallel processing.
o 3D CAD Applications: Python can be used for 3D computer-aided design
(CAD) applications through libraries such as Blender.
o Machine Learning: Python is widely used for machine learning due to its
simplicity, ease of use, and availability of powerful machine learning
libraries.
o Computer Vision or Image Processing Applications: Python can be
used for computer vision and image processing applications through
powerful libraries such as OpenCV and Scikit-image.
o Speech Recognition: Python can be used for speech recognition
applications through libraries such as SpeechRecognition and PyAudio.
o Scientific computing: Libraries like NumPy, SciPy, and Pandas provide
advanced numerical computing capabilities for tasks like data analysis,
machine learning, and more.
o Education: Python's easy-to-learn syntax and availability of many
resources make it an ideal language for teaching programming to
beginners.
o Testing: Python is used for writing automated tests, providing
frameworks like unit tests and pytest that help write test cases and
generate reports.
o Gaming: Python has libraries like Pygame, which provide a platform for
developing games using Python.
o IoT: Python is used in IoT for developing scripts and applications for
devices like Raspberry Pi, Arduino, and others.
o Networking: Python is used in networking for developing scripts and
applications for network automation, monitoring, and management.
o DevOps: Python is widely used in DevOps for automation and scripting of
infrastructure management, configuration management, and deployment
processes.
o Finance: Python has libraries like Pandas, Scikit-learn, and Statsmodels
for financial modeling and analysis.
o Audio and Music: Python has libraries like Pyaudio, which is used for
audio processing, synthesis, and analysis, and Music21, which is used for
music analysis and generation.
o Writing scripts: Python is used for writing utility scripts to automate
tasks like file operations, web scraping, and data processing.

Python Popular Frameworks and Libraries

Python has wide range of libraries and frameworks widely used in various fields
such as machine learning, artificial intelligence, web applications, etc. We define
some popular frameworks and libraries of Python as follows.

o Web development (Server-side) - Django Flask, Pyramid, CherryPy


o GUIs based applications - Tk, PyGTK, PyQt, PyJs, etc.
o Machine Learning - TensorFlow, PyTorch,
o Scikit-learn, Matplotlib, Scipy, etc.
o Mathematics - Numpy, Pandas, etc.
o BeautifulSoup: a library for web scraping and parsing HTML and XML
o Requests: a library for making HTTP requests
o SQLAlchemy: a library for working with SQL databases
o Kivy: a framework for building multi-touch applications
o Pygame: a library for game development
o Pytest: a testing framework for Python
o Django REST framework: a toolkit for building RESTful APIs
o FastAPI: a modern, fast web framework for building APIs
o Streamlit: a library for building interactive web apps for machine learning
and data science
o NLTK: a library for natural language processing

Variables
A variable is the name given to a memory location. A value-holding Python
variable is also known as an identifier. Variable names must begin with a letter
or an underscore, but they can be a group of both letters and digits. The name of
the variable should be written in lowercase.

Rules of Variable

o The variable's first character must be an underscore or alphabet (_).


o Every one of the characters with the exception of the main person might be a
letter set of lower-case(a-z), capitalized (A-Z), highlight, or digit (0-9).
o White space and special characters (!, @, #, %, etc.) are not allowed in the
identifier name. ^, &, *).

Python Data Types

Python Data Types are used to define the type of a variable. It defines what type
of data we are going to store in a variable. The data stored in memory can be of
many types. For example, a person's age is stored as a numeric value and his or
her address is stored as alphanumeric characters.

Python has various built-in data types

Numbers
Numeric values are stored in numbers. The whole number, float, and complex
qualities have a place with a Python Numbers datatype. Python offers the type()
function to determine a variable's data type. The instance () capability is utilized
to check whether an item has a place with a specific class.

a=5
print("The type of a", type(a))

b = 40.5
print("The type of b", type(b))

c = 1+3j
print("The type of c", type(c))
print(" c is a complex number", isinstance(1+3j,complex))

Output

The type of a <class 'int'>


The type of b <class 'float'>
The type of c <class 'complex'>
C is complex number: True

Python supports three kinds of numerical data.

○ Int: Whole number worth can be any length, like numbers 10, 2, 29, - 20, -
150, and so on. An integer can be any length you want in Python. Its worth
has a place with int.
○ Float: Float stores drifting point numbers like 1.9, 9.902, 15.2, etc. It can
be accurate to within 15 decimal places.
○ Complex: An intricate number contains an arranged pair, i.e., x + iy,
where x and y signify the genuine and non-existent parts separately. The
complex numbers like 2.14j, 2.0 + 2.3j, etc.

Sequence

Sequence is a collection data type. It is an ordered collection of items. Items in


the sequence have a positional index starting with 0. It is conceptually similar to
an array in C or C++. There are three sequence data types defined in Python.

❖ String Data Type


❖ List Data Type
❖ Tuple Data Type

String Data Type


The sequence of characters in the quotation marks can be used to describe the
string. A string can be defined in Python using single, double, or triple quotes.
String dealing with Python is a direct undertaking since Python gives worked-in
capabilities and administrators to perform tasks in the string.
In other word, Python string is a sequence of one or more Unicode characters,
enclosed in single, double or triple quotation marks (also called inverted
commas). Python strings are immutable which means when you perform an
operation on strings, you always produce a new string object of the same type,
rather than mutating an existing string.

The plus (+) sign is the string concatenation operator and the asterisk (*) is the
repetition operator in Python.

str = 'Hello World!'


print (str) # Prints complete string
print (str[0]) # Prints first character of the string
print (str[2:5]) # Prints characters starting from 3rd to 5th
print (str[2:]) # Prints string starting from 3rd character
print (str * 2) # Prints string two times
print (str + "TEST") # Prints concatenated string
Output
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST

List Data Type


Python Lists are the most versatile compound data types. A Python list contains
items separated by commas and enclosed within square brackets ([]).
A list can have items which are simple numbers, strings, tuple, dictionary, set or
object of user defined class also.

Example:
list1 = [1, "hi", "Python", 2]
#Checking type of given list
print(type(list1))

#Printing the list1


print (list1)

# List slicing
print (list1[3:])

# List slicing
print (list1[0:2])

# List Concatenation using + operator


print (list1 + list1)

# List repetation using * operator


print (list1 * 3)

Output
[1, 'hi', 'Python', 2]
[2]
[1, 'hi']
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2]
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2, 1, 'hi',
'Python', 2]

Tuple
A tuple is like a list. Tuples, like lists, also contain a collection of items
from various data types. A parenthetical space () separates the tuple's
components from one another.

Example:
tup = ("hi", "Python", 2)
# Checking type of tup
print (type(tup))

#Printing the tuple


print (tup)

# Tuple slicing
print (tup[1:])
print (tup[0:1])

# Tuple concatenation using + operator


print (tup + tup)

# Tuple repatation using * operator


print (tup * 3)

# Adding value to tup. It will throw an error.


t[2] = "hi"

Output
<class 'tuple'>
('hi', 'Python', 2)
('Python', 2)
('hi',)
('hi', 'Python', 2, 'hi', 'Python', 2)
('hi', 'Python', 2, 'hi', 'Python', 2, 'hi', 'Python', 2)

Traceback (most recent call last):


File "main.py", line 14, in <module>
t[2] = "hi";
TypeError: 'tuple' object does not support item assignment

You might also like