Python Unit 1
Python Unit 1
Python is a popular programming language. It was created by Guido van Rossum, and
released in 1991.
Python is an easy-to-learn yet powerful and versatile scripting language, which makes it
attractive for Application Development.
With its interpreted nature, Python's syntax and dynamic typing make it an ideal
language for scripting and rapid application development.
Python Version
Python programming language is being updated regularly with new features and
supports. There are lots of update in Python versions, started from 1994 to current
release.
Usage of Python
Python is a general purpose, open source, high-level programming language and also
provides number of libraries and frameworks. Python has gained popularity because of
its simplicity, easy syntax and user-friendly environment. The usage of Python as
follows.
Python Applications
Python is known for its general-purpose nature that makes it applicable in almost every
domain of software development. Python makes its presence in every emerging field. It
is the fastest-growing programming language and can develop any application.
Web Applications
We can use Python to develop web applications. It provides libraries to handle internet
protocols such as HTML and XML, JSON, Email processing, request, beautifulSoup,
Feedparser, etc.
The GUI stands for the Graphical User Interface, which provides a smooth interaction to
any application. Python provides a Tk GUI library to develop a user interface.
Console-based Application
Console-based applications run from the command-line or shell. These applications are
computer program which are used commands to execute. This kind of application was
more popular in the old generation of computers. Python can develop this kind of
application very effectively. It is famous for having REPL, which means the Read-Eval-
Print Loop that makes it the most suitable language for the command-line applications
Business Applications
Business Applications differ from standard applications. E-commerce and ERP are an
example of a business application. This kind of application requires extensively,
scalability and readability, and Python provides all these features.
3D CAD Applications
Python Variables
Variables are containers for storing data values. A variable is the name given to a
memory location. A value-holding Python variable is also known as an identifier.
Since Python is an infer language that is smart enough to determine the type of a
variable, we do not need to specify its type in Python.
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. Both Rahul and rahul are
distinct variables.
Identifier Naming
Identifiers are things like variables. An Identifier is utilized to recognize the literals
utilized in the program. The standards to name an identifier are given underneath
Declaring Variable and Assigning Values
Global Variables
Variables that are created outside of a function (as in all of the examples above) are
known as global variables. Global variables can be used by everyone, both inside of
functions and outside.
Python Data Types
Data types are the classification or categorization of data items. It
represents the kind of value that tells what operations can be performed on
a particular data. Since everything is an object in Python programming,
data types are actually classes and variables are instances (object) of
these classes. The following are the standard or built-in data types in
Python:
The numeric data type in Python represents the data that has a numeric
value. A numeric value can be an integer, a floating number, or even a
complex number. These values are defined as Python int, Python float, and
Python complex classes in Python.
Python String
Python List
Python Tuple
Lists are just like arrays, declared in other languages which is an ordered
collection of data. It is very flexible as the items in a list do not need to be of
the same type.
Tuple Data Type
Just like a list, a tuple is also an ordered collection of Python objects. The
only difference between a tuple and a list is that tuples are immutable i.e.
tuples cannot be modified after it is created. It is represented by a tuple
class.
Note – True and False with capital ‘T’ and ‘F’ are valid booleans otherwise
python will throw an error.
Set Data Type
In Python, a Set is an unordered collection of data types that is iterable,
mutable and has no duplicate elements. The order of elements in a set is
undefined though it may consist of various elements.
Sets can be created by using the built-in set() function with an iterable
object or a sequence by placing the sequence inside curly braces,
separated by a ‘comma’. The type of elements in a set need not be the
same, various mixed-up data type values can also be passed to the set.
Create a Dictionary
In Python, a Dictionary can be created by placing a sequence of elements
within curly {} braces, separated by ‘comma’. Values in a dictionary can be
of any datatype and can be duplicated, whereas keys can’t be repeated
and must be immutable. The dictionary can also be created by the built-in
function dict(). An empty dictionary can be created by just placing it in curly
braces{}. Note – Dictionary keys are case sensitive, the same name but
different cases of Key will be treated distinctly.
Operators in Python
In Python programming, Operators in general are used to perform
operations on values and variables. These are standard symbols used for
the purpose of logical and arithmetic operations. In this article, we will look
into different types of Python operators.
Arithmetic Operators
Bitwise Operators
In Python, is and is not are the identity operators both are used to check if
two values are located on the same part of the memory. Two variables that
are equal do not imply that they are identical.