0% found this document useful (0 votes)
6 views16 pages

Python Programming Features Overview

The document provides an overview of Python programming, detailing its features, applications, and basic structure. It covers topics such as Python's easy syntax, dynamic typing, object-oriented nature, and various libraries for different applications including web development, image processing, and game development. Additionally, it explains Python's data types, variables, identifiers, and the rules for naming them.

Uploaded by

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

Python Programming Features Overview

The document provides an overview of Python programming, detailing its features, applications, and basic structure. It covers topics such as Python's easy syntax, dynamic typing, object-oriented nature, and various libraries for different applications including web development, image processing, and game development. Additionally, it explains Python's data types, variables, identifiers, and the rules for naming them.

Uploaded by

veddhobi9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2

----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------

UNIT 2 Introduction to python 12 Marks

Q.1 – Explain features and application of Python Programming…………26

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.

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
8. Cross-platform Language
 Python can run equally on different platforms such as Windows, Linux, UNIX, and Macintosh,
etc. So, we can say that Python is a portable language.
9. Extensible
 It converts the program into byte code, and any platform can use that byte code.
10. Embeddable
 The code of the other programming language can use in the Python source code.
 We can use Python source code in another programming language as well.
11. GUI Programming Support
 Graphical User Interface is used for the developing Desktop application.
 PyQT5, Tkinter, Kivy are the libraries which are used for developing the web application.

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

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
Enterprise  Python can be used to create applications that can be used within an
Applications Enterprise or an Organization.
 Some real-time applications are OpenERP, Tryton, Picalo, etc.
Image Processing  Python contains many libraries that are used to work with the image.
Application  The image can be manipulated according to our requirements.
 Some libraries of image processing are given below.
1. OpenCV
2. Pillow
3. SimpleITK
 Python comes loaded with many useful extensions (libraries) that come in
handy for the development of interactive games.
Game  For instance, libraries like PySoy (a 3D game engine that supports Python 3)
Development and PyGame are two Python-based libraries used widely for game
development.
 Python is the foundation for popular games like Battlefield 2, Frets on Fire,
World of Tanks, Disney’s Toontown Online, Vega Strike, and Civilization-IV.
 AI and ML models and projects are inherently different from traditional
software models.
Artificial  When we talk about AI/ML projects, the tools and technologies used and the
Intelligence and skillset required is totally different from those used in the development of
Machine Learning conventional software projects.
 AI/ML applications require a language that is stable, secure, flexible, and is
equipped with tools that can handle the various unique requirements of such
projects.
 Python is the secret ingredient behind many operating systems as well, most
popularly of Linux distributions.
Operating  Linux-based Ubuntu’s Ubiquity Installer and Fedora and Red Hat Enterprise’s
Systems Anaconda Installer are coded in Python.
 Even Gentoo Linux leverages Python Portage (package management system).
Usually, Python is combined with the C programming language to design and
develop operating systems.

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------

Q.2 – Explain Basic Structure of Python Programming………….33-34

 The Structure Python Program


consists of three files such as: [Link]
,[Link] and [Link].
 The file model [Link] is chosen for high
level file.
 It is known as a simple text file of
statements. Files [Link] and [Link] are
module.
 Program is designed as single main,
high file with one or more supplement files.
 Python Statements In general, the interpreter reads and executes the statements line by line i.e
sequentially.
 In python high level file has Important path of control of your Program where you can start your
application.
 The library tools are also known as Module files.
 Modules are having top end of code.
 Python has large collection of modules known as .it contains many modules for GUI Design, Internet
and network scripting.

 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

print(a); print(b): print(c)

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
 Comments in Python:
 Symbols used for writing comments include Hash (#) or Triple Double Quotation marks (**).
 Hash is used in writing single line comments that do not span multiple lines.
 Triple Quotation Marks are used to write multiple line comments.
 Three triple quotation marks to start the comment and again three quotation marks to end the
comment.

Example:

 This is single comments

####### This example will not print Hello World #######


print('Hello World') #
 Multiline Comments
“”” This
is multiline
comments
“””

Q.3 – What is keyword? Explain it…………40

 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.

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------

Q.4– What is variable? What is identifier? Write rules ………40-41

Identifiers and Variables:


 A Python identifier is a name used to identify a variable, function, class, module or other object.
 An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero ormore
letters, underscores and digits (0 to 9).
 Python variable is also known as an identifier and used to hold value.
 In Python, we don't need to specify the type of variable because Python is a infer language and
smart enough to get variable type.
 Variable names can be a group of both the letters and digits, but they have to begin with a letter or
an underscore.
 Python is a case sensitive programming language. Thus, name and Name are two different
identifiers in Python.
 A variable is a name given to a memory location.
 It is the basic unit of storage in a program.
 The value stored in a variable can be changed during program execution. A variable is only a name
given to a memory location; all the operations done on the variable effects that memory location.
 A variable can have a short name (like x and y) or a more descriptive name (age, car_name).

Rules for Python variables:

1. A variable name must start with a letter or the underscore character


2. A variable name cannot start with a number
3. A variable name can only contain alpha-numeric characters and underscores (A-z. 0-9, and _)
4. Variable names are case-sensitive (age, Age and AGE are three different variables)

Valid Variable Invalid variable


myName=”kk Paramar” 2myname=”kk parmar”
My_name=”kk Paramar” My-name=”kk parmar”
_my_name’”kk parmar” My name=”kk parmar”
Myname2=”kk paramar”
MYNAME=”kk Parmar”

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

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
Q.5 – Explain Python data types and string ………….44

 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))

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
2. Sequence Type:
 In Python, sequence is the ordered collection of similar or different data types. Sequences allows to
store multiple values in an organized and efficient fashion.
 There are several sequence types in Python –
1. String
2. List
3. Tuple

1. String:

 A string is a sequence of characters that can be a combination of


letters, numbers, and special characters.
 It can be declared in python by using single quotes, double quotes, or
even triple quotes.
 These quotes are not a part of a string, they define only starting and
ending of the string. Strings are immutable, i.e., they cannot be
changed.
 Each element of the string can be accessed using indexing or slicing
operations.

 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

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
 Example:
# Declaring a list
L = [1, "a" , "string" , 1+2]
print(L)
L1=[0,1,2,3,4,5]
print(L1)

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
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------

Q.6 – Explain Difference between intermediate mode and script mode……………56

Aspect Intermediate Mode Script Mode


Purpose Typically used for quick experimentation and Used for writing complete Python scripts or
testing small code snippets or individual programs that can be saved and executed as
commands. standalone files.
Usage Typically used in interactive environments Used in integrated development environments
like the Python REPL (Read-Eval-Print Loop) (IDEs) or text editors where you write, edit, and
or Jupyter Notebook. run Python scripts.
Input Code is entered line by line or in small chunks. Entire script or program is written before
execution.
Output Immediate output is shown for each line or Output is displayed after the entire script is
command. executed.
Editing Easily edit and rerun individual lines or Editing usually involves modifying the script
commands. file, and you must rerun the entire script to see
changes.
Persistence No permanent file is created; code is not Code can be saved in a .py file for future use.
saved.
Complexity Suited for simple tasks, quick calculations, or Suitable for developing large, structured
exploring data interactively. applications and more complex tasks.
Debugging Limited debugging capabilities as you work Full debugging tools are available for the entire
line by line. script.
Reusability Not suitable for reusing code snippets easily. Ideal for creating reusable modules and
functions.
Examples Interactive data analysis, quick calculations, Writing web applications, automation scripts,
experimenting with libraries. scientific simulations, etc.

Q.7 – Explain Operator available in Python……………47.

 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
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------

Q.8 – Arithmetic Operators and Relational/comparison Operators with example………….48-49

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.

# Examples of Arithmetic Operator


a=9
b=4
# Addition of numbers
add = a + b
# Subtraction of numbers
sub = a - b
# Multiplication of number
mul = a * b
# Division(float) of number
div1 = a / b
# print results
print(add)
print(sub)
print(mul)
print(div1)
[Link] - 7600031265 [Link] - 9429235711
PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------

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.

# Examples of Comparison Operators

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)

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
Q.9 – Logical Operators, bitwise and Assignment Operators with example…………….50-51

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.

# Examples of Assignment Operators


a = 10
# Assign value
b=a
print(b)
# Add and assign value
b += a
print(b)
# Subtract and assign value
b -= a
print(b)
# multiply and assign
b *= a
print(b)
#bitwise_lishift operator
b <<= a
print(b)
[Link] - 7600031265 [Link] - 9429235711
PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
Logical Operators:
 The logical operators are used primarily in the expression evaluation to make a decision.
 Python supports the following logical operators.

# Examples of Logical Operator


a = True
b = False
# Print a and b is False
print(a and b)
# Print a or b is True
print(a or b)
# Print not a is False
print(not a)

Bitwise Operators:
 The bitwise operators perform bit by bit operation on the values of the two operands.
 Consider the following example.

# Examples of Bitwise operators


a = 10 ,b = 4
# Print bitwise AND operation
print(a & b)
# Print bitwise OR operation
print(a | b)
# Print bitwise NOT operation
print(~a)
# print bitwise XOR operation
print(a ^ b)
# print bitwise right shift operation
print(a >> 2)
# print bitwise left shift operation
print(a << 2)

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------

Q.10 – Explain identity and Membership Operator with example………52-53

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.

# Python program to illustrate not 'in' operator


x = 24
y = 20
list = [10, 20, 30, 40, 50]

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)

[Link] - 7600031265 [Link] - 9429235711


PRAYOSHA ENGINEERING CLASSES SUB: PYTHON | UNIT 2
----------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------
Q.11 – Explain Type Conversion

 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.

 Python has two types of type conversion.


1. Implicit Type Conversion
2. Explicit Type Conversion

1. Implicit Type Conversion:


 During the implicit type conversion, the user is not supposed to mention any specific data type
during the conversion.
 The following program illustrates how it can be done in Python.
#program to demonstrate implicit type conversion
a = 10
print("The type of a is ", type(a))
b = 4.5
print("The type of b is ", type(b))
c=a+b
print(c)
print(“The type of c is ", type(c))

2. Explicit Type Conversion:


 In this type conversion, the user is supposed to pass the value in a function to obtain the
required data type.
 The int(), float() and str() are mostly used for the explicit type conversion.
#program to demonstrate explicit type conversion
a=10.6
print("The type of 'a' before typecasting is ",type(a))
print(int(a))
print("The type of 'a' after typecasting is",type(a))
b=7
print("The type of 'b' before typecasting is ",type(b))
print(float(b))
print("The type of 'b' after typecasting is",type(b))

[Link] - 7600031265 [Link] - 9429235711

You might also like