Python Programming Features Overview
Python Programming Features Overview
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
1. Easy Language
Python is an easy language. It is easy to read, write, learn and understand.
Python has a smooth learning curve. It is easy to learn.
Python has a simple syntax and Python code is easy to understand.
2. Readable
Reading a Python code is like reading an English sentence.
Python is best for beginners.
Python uses indentation instead of curly braces, This makes: the code looks clean and easier to
understand.
3. Interpreted Language
Python is an interpreted language; it means the Python program is executed one line at a time.
It makes debugging easy and portable.
It comes with the IDLE (Interactive Development Environment).
This is an interpreter and follows the REPL structure (Read-Evaluate-Print-Loop). .
4. Dynamically-Typed Language
In Python, we don't need to specify the data-type of the variable.
When we assign some value to the variable, it automatically allocates the memory to the variable
at run time.
Suppose we are assigned integer value 15 to x, then we don't need to write int x = 15.
Just write x = 15.
5. Object-Oriented Language
Python supports object-oriented language and concepts of classes and objects.
The object-oriented procedure helps to programmer to write reusable code and develop
applications in less code.
It supports inheritance, polymorphism, and encapsulation, etc.
6. Free and Open Source
Python is freely available for everyone.
It is freely available on its official website [Link].
The open-source means, "Anyone can download its source code without paying any penny."
7. Large Standard Library
It provides a huge range of libraries for the various fields such as machine learning, web
developer, and also for the scripting.
There are various machine learning libraries, such as Tensor flow, Pandas, Numpy, Keras, and
Pytorch, etc.
Django, flask, pyramids are the popular framework for Python web development.
Applications Description
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.
One of Python web-framework named Django is used on Instagram.
Web Applications Python provides many useful frameworks, and these are given below:
1. Django and Pyramid framework (Use for heavy applications)
2. Flask and Bottle (Micro-framework)
The GUI stands for the Graphical User Interface, which provides a smooth
interaction to any application.
Desktop GUI Python provides a Tk GUI library to develop a user interface.
Applications Some popular GUI libraries are given below.
1. Tkinter or Tk
2. wxWidgetM
Python is useful for the software development process.
It works as a support language and can be used to build control and
Software management, testing, etc.
Development 1. SCons is used to build control.
2. Buildbot and Apache Gumps are used for automated continuous
compilation and testing.
3. Round or Trac for bug tracking and project management.
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.
3D CAD Python can create a 3D CAD application by using the following functionalities.
Applications 1. Fandango (Popular)
2. HeeksCNC
3. AnyCAD
4. RCAM
Python Statements:
Python programs are typically organized with one statement per line.
In other words, each statement occupies a single line, with the end of the statement delimited by the
newline character that marks the end of the line.
Example: print('Welcome to python programming")
Multiple Statements per Line We can also write multiple statements per line, but it is not a good
practice as it reduces the readability of the code.
For Example
a = 10; b = 20; c = b + a
Example:
Keywords are reserved words and you cannot use them as constant or variable or any other identifier
names.
All the Python keywords contain lowercase letters only except True, False and None this are the only
keywords with uppercase letters.
Example:
name=”kk parmar” #declare variable
age=12 #declare variable
a=b=c=20 #assigning a single value to multiple variable
a,b,c=1,12,123 #assigning a different value to multiple variable
Data Types:
Variables can hold values, and every value has a data-type.
Python is a dynamically typed language; hence we do not need to define the type of the variable
while declaring it
A variable can hold different types of values.
For example, a person's name must be stored as a string whereas its id must be stored as an
integer.
Python provides various standard data types that define the storage method on each of them.
The data types defined in Python are given below:
1. Numbers
2. String
3. List
4. Tuple
5. Dictionary
1. Numbers:
In Python, numeric data type represents the data which has numeric value. Numeric value can be
integer, floating number or even complex numbers.
1. Integers – This value is represented by int class. It contains positive or negative whole
numbers (without fraction or decimal). In Python there is no limit to how long an integer
value can be.
2. Float – This value is represented by float class. It is a real number with 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.
3. Complex Numbers – Complex number is represented by complex class. It is specified as (real
part) + (imaginary part) j. For example – 2+3j.
Note – type () function is used to determine the type of data type.
# Python program to demonstrate numeric value
a=5
print("Type of a: ", type(a))
b = 5.0
print("\nType of b: ", type(b))
c = 2 + 4j
print("\nType of c: ", type(c))
1. String:
Example:
# Assigning string to a variable
a = 'HELLO
print (a)
b = "'HELLO "
print (b)
c= ''''HELLO
print (c)1
2. List
Lists are one of the most powerful data structures in python. Lists
are sequenced data types.
In Python, an empty list is created using list[]function. They are just like the arrays declared in
other languages.
But the most powerful thing is that list need not be always homogeneous. A single list can contain
strings, integers, as well as other objects.
Lists can also be used for implementing stacks and queues. Lists are mutable, i.e., they can be
altered once declared.
The elements of list can be accessed using indexing and slicing operations
3. Tuple:
A tuple is a sequence of immutable Python objects.
Tuples are just like lists with the exception that tuples
cannot be changed once declared.
Tuples are usually faster than lists.
Placing different values separated by commas and enclosed in parentheses forms a tuple.
Example:
tup = (1, "a", "string", 1+2)
print(tup)
print(tup[1])
3. Dictionary:
Dictionary in Python is a collection of keys values, used to store data values like a map, which,
unlike other data types which hold only a single value as an element.
Dictionary holds key: value pair.
Key-Value is provided in the dictionary to make it more optimized.
1. Keys must be a single element
2. Value can be any type such as list, tuple, integer, etc.
In other words, we can say that a dictionary is the collection of key-value pairs where the value can
be any Python object.
In contrast, the keys are the immutable Python object, i.e., Numbers, string, or tuple.
Example:
Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"}
print(type(Employee))
print("printing Employee data .... ")
print(Employee)
Output:
<class 'dict'>
Printing Employee data ....
{'Name': 'John', 'Age': 29, 'salary': 25000, 'Company': 'GOOGLE'}
[Link] - 7600031265 [Link] - 9429235711
PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
The operator can be defined as a symbol which is responsible for a particular operation between
two operands.
Operators are the pillars of a program on which the logic is built in a specific programming
language.
Python provides a variety of operators, which are described as follows.
1. Arithmetic operators
2. Comparison operators
3. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
[Link] - 7600031265 [Link] - 9429235711
PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
1. Arithmetic Operators:
Arithmetic operators are used to perform arithmetic operations between two operands. It includes +
(addition), - (subtraction), *(multiplication), /(divide), %(reminder), //(floor division), and exponent
(**) operators.
Consider the following table for a detailed explanation of arithmetic operators.
2. Comparison operator:
Comparison operators are used to comparing the value of the two operands and returns
Boolean true or false accordingly.
The comparison operators are described in the following table.
a = 13
b = 33
# a > b is False
print(a > b)
# a < b is True
print(a < b)
# a == b is False
print(a == b)
# a != b is True
print(a != b)
# a >= b is False
print(a >= b)
# a <= b is True
print(a <= b)
Assignment Operators:
The assignment operators are used to assign the value of the right expression to the left
operand.
The assignment operators are described in the following table.
Bitwise Operators:
The bitwise operators perform bit by bit operation on the values of the two operands.
Consider the following example.
5. Membership Operators:
Python membership operators are used to check the membership of value inside a Python
data structure.
If the value is present in the data structure, then the resulting value is true otherwise it
returns false.
if (x not in list):
print("x is NOT present in given list")
else:
print("x is present in given list")
if (y in list):
print("y is present in given list")
else:
print("y is NOT present in given list")
6. Identity Operators:
The identity operators are used to decide whether an element certain class or type.
a = 10
b = 20
c=a
print(a is not b)
print(a is c)
The process of converting the value of one data type (integer, string, float, etc.) to another data
type is called type conversion.
Type Conversion is the conversion of object from one data type to another data type.
Implicit Type Conversion is automatically performed by the Python interpreter.
Python avoids the loss of data in Implicit Type Conversion.
Explicit Type Conversion is also called Type Casting; the data types of objects are convertedusing
predefined functions by the user.
In Type Casting, loss of data may occur as we enforce the object to a specific data type.