Final
Final
2022-23
COMPUTER
SCIENCE
SUBMITTED BY- SARTHAK GOYAL
P
PYTHON
PROJECT WORK
PROJECT WORK
ACKNOWLEDGMENT
I am glad to present my computer project. This
project was given by our respected computer
teacher Neha Saxena Mam. I am really thankful
to her for giving us such a wonderful and
interesting topic for our project.
___________ ____________
Subject Teacher Principal
INDEX
1. INTRODUCTION
2. HISTORY OF PYTHON
3. APPLICATIONS OF PYTHON
4. ADVANTAGES OF PYTHON
5. DISADVANTAGES OF PYTHON
6. TOKENS IN PYTHON
7. KEYWORDS
8. IDENTIFIRES
9. LITERALS
10. OPERATORS
11. BAREBONES OF A PYTHON PROGRAM
12. FLOW CONTROL STATEMENTS
13. LOOPING
INTRODUCTION
Python is a high-level, general-purpose programming language.
Its design philosophy emphasizes code readability with the use
of significant indentation.
1
HISTORY OF
PYTHON
Python was conceived in the late 1980s by Guido van Rossum
at Centrum Wiskunde & Informatica (CWI) in the Netherlands as
a successor to the ABC programming language, which was
inspired by SETL, capable of exception handling and interfacing
with the Amoeba operating system. Its implementation began in
December 1989, Van Rossum shouldered sole responsibility for
the project, as the lead developer, until 12 July 2018, when he
announced his "permanent vacation" from his responsibilities as
Python's "benevolent dictator for life", a title the Python
community bestowed upon him to reflect his long-term
commitment as the project's chief decision-maker. In January
2019, active Python core developers elected a five-member
Steering Council to lead the project.
2
code could not easily be forward-ported to Python 3. No further
security patches or other improvements will be released for
it. Currently only 3.7 and later are supported. In 2021,
Python 3.9.2 and 3.8.8 were expedited as all versions of Python
(including 2.7) had security issues leading to possible remote
code execution and web cache poisoning.
In 2022, Python 3.10.4 and 3.9.12 were expedited and 3.8.13, and
3.7.13, because of many security issues. When Python 3.9.13 was
released in May 2022, it was announced that the 3.9 series
(joining the older series 3.8 and 3.7) will only receive security
fixes going forward. On September 7, 2022, four new releases
were made due to a potential denial-of-service attack: 3.10.7,
3.9.14, 3.8.14, and 3.7.14.
3
APPLICATIONS
OF PYTHON
1. Web Development
4
• Numpy for complex data analysis
• Keras for Machine learning
• SciPy for technical computing
• Seaborn for data visualization
3. Data Science
Data science involves data collection, data sorting, data
analysis, and data visualization. Python provides amazing
functionality to tackle statistics and complex mathematical
calculations. The presence of in-built libraries provides
convenience to data science professionals. Some of the
popular libraries that provide ease in the data science process
are TensorFlow, Pandas, and Socket learning. These libraries
provide an ecosystem for fine-tuning data models, data
preprocessing, and performing complex data analysis.
4. Game Development
6. Software Development
7. CAD Applications
6
CAD refers to computer-aided design; it is the process of
creating 3D and 2D models digitally. This application has
replaced manual drift and is used by architects, product
designers, and construction managers to design products with
extremely high consistency. Python is embedded with amazing
applications like Blender, FreeCAD, open cascade, and a lot
more to efficiently design products. These provide enhanced
features like technical drawing, dynamic system development,
recordings, file export, and import.
8. Business Applications
9. Desktop GUI
7
libraries like them to build a fully functional GUI in an
extremely secure and efficient manner.
8
ADVANTAGES
OF PYTHON
1.Simple to Use and Understand
For newcomers, Python is simple to understand and use. It's a
highly developed programming language with an English-like
syntax. The language is simple to adapt as a result of these
factors. Because of its simplicity, Python's fundamentals can be
implemented faster than those in other programming
languages.
2.Free and Open-Source
Python is distributed under an open-source license approved by
the Open-Source Initiative (OSI). As a result, users can work on
it and distribute it. Users can download the source code, modify
it, and even distribute their Python version. Companies that wish
to modify a specific behavior and build their version will benefit.
3.Productivity has Increased
Users can create new kinds of applications using the Python
programming language. Because of its versatility, this language
permits the operator to try new things. Because of the language,
the user is not prevented from trying something new. Python is
favored in these scenarios since other programming languages
lack the flexibility and freedom that Python does.
9
4.Interpreted Language
It is an interpreted language, implying that the code is
implemented line by line. This is one of the features that makes
it simple to use. In the event of an error, it halts the process and
reports the problem. Python only shows one error, even if the
program has multiple errors. This makes debugging easier.
5.Extensive library
Python includes a huge number of libraries that the user can
use. The standard library in Python is immense, and it includes
almost every function imaginable. Large and supportive
communities, as well as corporate sponsorship, have
contributed to this. When working with Python, users do not
need to use external libraries.
6.Dynamically Typed
Until we run the program, Python has no idea what kinds of
parameter we're talking about. It allocates the data type
automatically during execution. Variables and their data types
do not need to be declared by the programmer.
7.Portability
Many other languages, including C/C++, demand that user must
change their code to run on different platforms. Python, on the
contrary, is not equivalent to other programming languages. It
only needs to be written once, and then it can be run anywhere.
10
However, the user should avoid involving any system-
dependent features.
8.Supportive community
Python is a programming language generated many years ago
and has a large community that can assist programmers of all
experience levels, from rookies to specialists. Python's
community has helped it grow quickly in comparison to other
languages. The Python programming language comes with many
guides, instructional videos, and highly understandable
documentation to help developers learn the language faster and
more effectively.
11
DISADVANTAGES
OF PYTHON
1.Speed
Python is slower than C or C++. But of course, Python is a high-
level language, unlike C or C++ it's not closer to hardware.
2.Mobile Development
Python is not a very good language for mobile development . It
is seen as a weak language for mobile computing. This is the
reason very few mobile applications are built in it like
Carbonnelle.
3.Memory Consumption
Python is not a good choice for memory intensive tasks. Due to
the flexibility of the data-types, Python's memory consumption
is also high.
4.Database Access
Python has limitations with database access . As compared to
the popular technologies like JDBC and ODBC, the Python's
database access layer is found to be bit underdeveloped
and primitive .
5.Runtime Errors
Python programmers cited several issues with the design of the
language. Because the language is dynamically typed , it
requires more testing and has errors that only show up
at runtime .
12
TOKENS IN
PYTHON
Tokens. Python breaks each logical line into a sequence of
elementary lexical components known as tokens. Each token
corresponds to a substring of the logical line.
>Identifiers
> Keywords
>Operators
>Literals
>Punctuators
13
KEYWORDS
Python has a set of keywords that are reserved words that
cannot be used as variable names, function names, or any other
identifiers:
Keyword Description
as To create an alias
14
def To define a function
15
global To declare a global variable
16
or A logical operator
17
IDENTIFIRES
Identifiers are the name given to variables, classes, methods,
etc. For example,
language = “Python”
Continue = “Python”
18
• It's a convention to start an identifier with a letter rather _.
• Whitespaces are not allowed.
• We cannot use special symbols like !, @, #, $, and so on.
score @core
return_value return
name1 1name
19
Things to Remember
Python is a case-sensitive language. This
means, Variable and variable are not the same.
Always give the identifiers a name that makes sense. While c =
10 is a valid name, writing count = 10 would make more sense,
and it would be easier to figure out what it represents when you
look at your code after a long gap.
Multiple words can be separated using an underscore,
like this_is_a_long_variable.
20
LITERALS
Python literals constant or fixed values in the source code that
do not change during the execution of a program. Literals can
also be defined as the raw values that are given to Python
variables.
21
Numeric Literals
These literals contain only immutable numeric values. By
immutable, we mean that the values cannot be changed during
runtime.
From Python 3 onwards, numeric literals have three subtypes:
• Integers
• Float
• Complex
Integers
All the natural numbers – negative, zero, or positive are
integers. They can also be categorized into the following types:
• Decimal integers – contain digits from 0 to 9. The base for
decimal values is 10.
• Binary integers – contain only two digits- 0 and 1. The base for
binary values is 2 and prefixed with “0b”.
• Octal integers – contain the digits from 0 to 7. The base for
octal values is 8. In Python, the octal values are prefixed with
“0o”.
• Hexadecimal integers – Contain digits from 0 to 9 and
alphabets from A to F.
• examples of integer literals:
#Positive
x = 734
22
#Negative
y = -8672
#Binary
a = 0b111001100
#Decimal
b = 21
#Octal
c = 0o544
#Hexadecimal
d = 0xC9
print (x,y)
print(a, b, c, d)
Output:
Float
23
Float literals or floating-point literals contain numeric values in
decimal points. They are also sometimes referred to as real
literals. They are categorized into two main types:
• Fractional – contain whole numbers and decimal points.
#Positive
x = 1090.0
#Negative
y = -227.0
• Exponential – these values are represented in the powers of
10, represented by the letter e or E. The digits before the
symbol E in an exponential literal are known as
the mantissa and the digits succeeding the symbol E are
the exponent. The exponent value describes the placement of
the decimal point.
#Positive
print(25.53E3) #Decimal point will jump 3 places
#Negative
print(-105.03E5) #Decimal point will jump 5 places
Output:
24
Complex
Complex literals are represented as X+Yj, where X is the real
part of the value and Yj is the imaginary or complex part.
Here,j=-1 examples of complex literals are:
#Positive
print(12 + 8j)
#Negative
print(-5j)
Output:
String Literals
25
examples of string literals:
#Single line string literals
print('Python Tutorial')
Output:
26
a
Python
Tutorial"""
print(str)
Output:
Boolean Literals
These literals take only two values: True (aka 1) and False (aka
0).
Let’s look at the below example:
#Boolean Literals
x = 1.0
a = (x == 1)
print("a is", a)
b = (x == 7)
print("b is", b)
Output:
27
OPERATORS
Python Operators
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.
o Arithmetic operators
o Comparison operators
o Assignment Operators
o Logical Operators
o Bitwise Operators
o Membership Operators
o Identity Operators
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.
28
Operator Description
/ (divide) It returns the quotient after dividing the first operand by the
second operand. For example, if a = 20, b = 10 => a/b = 2.0
% (reminder) It returns the reminder after dividing the first operand by the
second operand. For example, if a = 20, b = 10 => a%b = 0
// (Floor division) It gives the floor value of the quotient produced by dividing
the two operands.
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.
29
Operator Description
<= If the first operand is less than or equal to the second operand,
then the condition becomes true.
>= If the first operand is greater than or equal to the second operand,
then the condition becomes true.
> If the first operand is greater than the second operand, then the
condition becomes true.
< If the first operand is less than the second operand, then the
condition becomes true.
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.
Operator Description
30
+= It increases the value of the left operand by the value of the right
operand and assigns the modified value back to left operand. For
example, if a = 10, b = 20 => a+ = b will be equal to a = a+ b and
therefore, a = 30.
-= It decreases the value of the left operand by the value of the right
operand and assigns the modified value back to left operand. For
example, if a = 20, b = 10 => a- = b will be equal to a = a- b and
therefore, a = 10.
*= It multiplies the value of the left operand by the value of the right
operand and assigns the modified value back to then the left
operand. For example, if a = 10, b = 20 => a* = b will be equal to a = a*
b and therefore, a = 200.
%= It divides the value of the left operand by the value of the right
operand and assigns the reminder back to the left operand. For
example, if a = 20, b = 10 => a % = b will be equal to a = a % b and
therefore, a = 0.
**= a**=b will be equal to a=a**b, for example, if a = 4, b =2, a**=b will
assign 4**2 = 16 to a.
Bitwise Operators
The bitwise operators perform bit by bit operation on the values
of the two operands. Consider the following example.
For example,
31
1. if a = 7
2. b=6
3. then, binary (a) = 0111
4. binary (b) = 0110
5.
6. hence, a & b = 0011
7. a | b = 0111
8. a ^ b = 0100
9. ~ a = 1000
Operator Description
& (binary and) If both the bits at the same place in two operands are 1, then 1 is
copied to the result. Otherwise, 0 is copied.
| (binary or) The resulting bit will be 0 if both the bits are zero; otherwise, the
resulting bit will be 1.
^ (binary xor) The resulting bit will be 1 if both the bits are different; otherwise,
the resulting bit will be 0.
~ (negation) It calculates the negation of each bit of the operand, i.e., if the bit
is 0, the resulting bit will be 1 and vice versa.
<< (left shift) The left operand value is moved left by the number of bits present
in the right operand.
>> (right shift) The left operand is moved right by the number of bits present in
the right operand.
32
Logical Operators
The logical operators are used primarily in the expression
evaluation to make a decision. Python supports the following
logical operators.
Operator Description
and If both the expression are true, then the condition will be true. If a
and b are the two expressions, a → true, b → true => a and b →
true.
not If an expression a is true, then not (a) will be false and vice versa.
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.
Operator Description
33
not in It is evaluated to be true if the first operand is not found in the
second operand (list, tuple, or dictionary).
Identity Operators
The identity operators are used to decide whether an element
certain class or type.
Operator Description
Operator Precedence
The precedence of the operators is essential to find out since it
enables us to know which operator should be evaluated first.
The precedence table of the operators in Python is given below.
Operator Description
** The exponent operator is given priority over all the others used in
the expression.
34
* / % // The multiplication, divide, modules, reminder, and floor division.
<= < > >= Comparison operators (less than, less than equal to, greater than,
greater then equal to).
35
BAREBONES
OF A PYTHON
PROGRAM
The barebones of python program are Expressions, Statements,
Comments, Functions and Block & Indentation.
1. Expression:
Expression is evaluated and produces the results.
Ex: (10=2)/2
2. Statements:
Indicates that we are doing something.
Ex: a=10
print("Calling in proper sequence")
3. Comments:
Comments are readable messages for a programmer but it
is overlooked by the python interpreter.
a. Single line comment (#)
b. Multi-line comment (''' ''')
Ex: #this is a single-line comment
''' this is
multiple '''
4. Function:
A function is a block of code which only runs when it is
called. Ex: getStudentMarks()
36
5. Block & Indentation:
A group of statements in block indentation at the same level
creates a block. Ex: all the statements that are under the
function getStudentMarks()
37
FLOW CONTROL
STATEMENTS
The order of execution of the statements in a program is known
as flow of control. The flow of control can be implemented using
control structures. Python supports two types of control
structures—selection and repetition.
1. If – Else Statement
2. Elif Statement
3. Nested If Statement
38
path gets executed. The syntax for if..else statement is as
follows.
>>Elif Statement
39
if condition:
statement(s)
elif condition:
statement(s)
elif condition:
statement(s)
else:
statement(s)
Example:
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
Indentation
40
LOOPING
Looping – The ability to repeatedly run a group of statements in
a programme based on a condition is provided by looping
constructs. While a certain logical condition is true, the
statements in a loop are repeated again.
>>For Loop
41
Example:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
while test_condition:
body of while
Example:
i = 1
while i < 6:
print(i)
i += 1
42
>>Nested Loops
A loop may contain another loop inside it. A loop inside another
loop is called a nested loop. Python does not impose any
restriction on how many loops can be nested inside a loop or on
the levels of nesting. Any type of loop (for/while) may be nested
within another loop (for/while).
Example:
adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
for x in adj:
for y in fruits:
print(x, y)
43