0% found this document useful (0 votes)
11 views

Python Unit 1

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

Python Unit 1

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

What is Python

Python is a popular programming language. It was created by Guido van Rossum, and
released in 1991.

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 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 supports multiple programming patterns, including object-oriented, imperative,


and functional or procedural programming styles.

Python is not intended to work in a particular area, such as web programming. It is a


multipurpose programming language because it can be used with web, enterprise, 3D
CAD, etc.

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.

Desktop GUI Applications

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

The CAD (Computer-aided design) is used to design engineering related architecture. It


is used to develop the 3D representation of a part of a system.

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

• Python doesn't tie us to pronounce a variable prior to involving it in the


application. It permits us to make a variable at the necessary time.
• In Python, we don't have to explicitly declare variables. The variable is declared
automatically whenever a value is added to it.
• The equal (=) operator is utilized to assign worth to a variable.

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:

Numeric Data Type

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.

• Integers – This value is represented by int class. It contains positive


or negative whole numbers (without fractions or decimals). In Python,
there is no limit to how long an integer value can be.
• Float – This value is represented by the float class. It is a real number
with a floating-point representation. It is specified by a decimal point.
Optionally, the character e or E followed by a positive or negative
integer may be appended to specify scientific notation.
• Complex Numbers – Complex number is represented by a complex
class. It is specified as (real part) + (imaginary part)j. For example –
2+3j
Sequence Data Type

The sequence Data Type in Python is the ordered collection of similar or


different data types. Sequences allow storing of multiple values in an
organized and efficient fashion. There are several sequence types in
Python –

Python String

Python List

Python Tuple

String Data Type

Strings in Python are arrays of bytes representing Unicode characters. A


string is a collection of one or more characters put in a single quote,
double-quote, or triple-quote. In python there is no character data type, a
character is a string of length one. It is represented by str class.

List Data Type

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.

In Python, tuples are created by placing a sequence of values separated by


a ‘comma’ with or without the use of parentheses for grouping the data
sequence. Tuples can contain any number of elements and of any datatype
(like strings, integers, lists, etc.). Note: Tuples can also be created with a
single element, but it is a bit tricky. Having one element in the parentheses
is not sufficient, there must be a trailing ‘comma’ to make it a tuple.

Boolean Data Type


Data type with one of the two built-in values, True or False. Boolean
objects that are equal to True are truthy (true), and those equal to False are
falsy (false). But non-Boolean objects can be evaluated in a Boolean
context as well and determined to be true or false. It is denoted by the class
bool.

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.

Create a Set in Python

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.

Dictionary Data Type


A dictionary in Python is an unordered collection of data values, used to
store data values like a map, unlike other Data Types that hold only a
single value as an element, a Dictionary holds a key: value pair. Key-value
is provided in the dictionary to make it more optimized. Each key-value pair
in a Dictionary is separated by a colon : , whereas each key is separated by
a ‘comma’.

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

Python Arithmetic operators are used to perform basic mathematical


operations like addition, subtraction, multiplication, and division.

In Python 3.x the result of division is a floating-point while in Python 2.x


division of 2 integers was an integer. To obtain an integer result in Python
3.x floored (// integer) is used
Comparison Operators

In Python Comparison of Relational operators compares the values. It


either returns True or False according to the condition
Logical Operators

Bitwise Operators

Python Bitwise operators act on bits and perform bit-by-bit operations.


These are used to operate on binary numbers
Assignment Operators
Identity 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.

You might also like