Python
Python
Python is a
popular high-level
pu eprogramming,
1989. Python is
extensive
programming
Put Programming
as
language. It is powerful language used
lang 8ene
a tor
INSTALLING PYTHON
Follow these steps to download and instll the Python software:
Step 1: Open the website http://www.python.orgldownloads.
Step 2: Click on the Download Python 3.8.3 button.
Introduction to P
OVARIABLES IN PYTHON
aabies are memory reference points where we store values which can be accesed or chaniged
r h e hames the variables
given to are known as ldentifiers. In Python, we oo opecity
p eot variable because Python is a dynamically typed language and it identies the varinble type
utomatically. Let's understand this with the help of the glven examplies.
num 0.4
Price 30.3
TOTAL round(price num,2)
print (ToTAL)
a 10
20
PELnt a a)
print ("b-", b}
20 and b - 40 will be printed. You can also assign the same value
On the output screen, a
to multiple variables at the time in the following way:
a b 20
print ("a", a)
print ("b=", b)
You must follow the given rules while creating and naming the variables:
fatest
version
for Windoy
Downtoad
the
Downiloading Pytho
can either
software.
You
downloaded
software
in t h e
on the the
o r locate
Double-click
Step 3 screen
b o t t o m of the WarningB
l o o k at the The Security
computer.
folder of your
Downloads
dialog box appeas window appears.
in Interactive Mode
Working which gives
immediate
command line shell
Interactive Mode is a one
i n t e r a c t i v e mode,
we type
command. In
result for each command and gives
command at a time. Python
the executes given
the output.
Mode:
and work in Interactive
Follow these steps to start Python
Click on Start button.
Step 1
Scroll down the list of programs
and click on Python 3.8
Step 2:
yh 3
inputprintpy-C/Usenv/ADMIN/AppDsta
Ele dieFgrmat Bun gptionsondow Bep Python 3.c.3 (tag/v.8.3:6tic32, May 13 2020.
age1nput (Enter your age:) 22:3702) C w.1924 64 bit (ND64)1 on win32
P pyEight credita or 1icens
name1nput (Enter your name:) N tomatkon
print (name, "your age is", age)
BESTART: CrUsers/AKDN/Appbata/ Local/ Progtas
YeRon/rEhonaAnputpeint-py
Ankcit your age is 2
In3 Colt 23
Using input(0 and print) functions
Introduction to Programming
of Python Window
ponents
Thereea two components of Python loLE window
e n u Barn The Meru Bar of Python iOLE window is similar t o t h e Menu Bar of other program
u s mernts such as File, Edit, shell, Debug, Optiorns, Window and Help.
Menu bar
Prompt
Components of 1DLE
Type the commands at the prompt and you will immediately get the results. Simply, type
press the Enter key. The result 6 appears on the screen. Try more values and see what hapr
6/ 2
3.0
yping commands
Introductio
A variable name can only contain
numbersap terscores (
atpharnurneric characters (al the letters of the alphalbet and
Vartable narnes are
case sensitive
Variable names Cannot contan arny special character or symbol
OLer's CATCH UP
Circle the incorrect variable in the
following code.
Roll no- 201 Student Name"Chirag
Section -'A
DATA TYPES
A data type specifies the type of value a variable can contains. For example,
be stored as a
string value whereas the
person's age must
a
person's name must
be stored as
Python are: an integer. Data types in
.int: Positive or
negative
whole numbers
(without any fractions). Example: a 3
float: Any real number in which a fraction is
denoted by a decimal symbol.
string:A string value is a collection of one or more
Example: a 35
characters put in single or
Example: a="hello" double quotes
cOMMENTS IN PYTHON
Comments Python can be used to explain parts of the code. It can also be
in
used to hide the coem
as well. Comments enable us to understand the way a program works. In
python, any stateme
starting with # symbol is known as a comment. Python does
not execute comments. Commentsa
not part of the program, but they do enhance the interactivity of the program and make it reada
a
Introduction to Prograrmn
of the above pro8ram is:
The result
4 cceg/ r 9 , Hay 13
help eedits or
3636, 333627 MC. 1924
1ionss 0 tor m
nto
atsonal eperstore.py
dpak/Aepbata/lecsl/Progtamn/yt h 39/tel
PRECEDENCE OF OPERATORS
Precedence of operators determines the order in which the
orecedence in
Python is listed in the operators are executed. The operat
following table. The highest
precedence is at the top
Operatoor
Name
Parenthesis
Exponent
Multiplication, Division, Modulo, Floor Division
Addition, Subtraction
Comparison
+, 5,**=, ll=Assignment
and, or, not
Logical
aub a-b
print ('Difference ot two numbers ias', aub)|
Introduction to Programm
Example Output
Name Destrigtion (eu7 arnd ys
Floor or integerOvides ond cuts the fractional part from the IlY
divis result
Program To perform all tfhe arithmetic operators
pkas
Formation.
-RESTART C/Uaeta/deepak/Appbata/l4ocal/Progtama/Python/Pytbo
n38/Arkthmetie operatoEs.py
13
6561
Introduction to Pm
Mullpfo- ine Commo
iert
9 P or so
fnange Heio orld
(Prngrwm
prHCHoWorey A
priHa)
print("Akshe
5 5619A.Yo t
guotes( " o )
s0 60eted
insde toiple
However, he teatfowritten
wrte
t n e
6omnerts:
For e s a r n g i e
e e gotes
Muls31e
OR Comens#n
MulEEEe
Consent'7
oPERATORS o n perform
aimetic and logr
special syritvols
are caed oper ariis. For evange,
be defined as
dan
In Python, operators use to get the oupt
the operators
computation.
The values whicdh
and the minus ( sgn is the operstor,
10-5, 10 and 5 are operands
in the expression
in the folloing.categories,
Python divldes the operators
ACTOPEPA
Gooe
----
The name Python Lars BAeK-Up
Python isa popular highlevel programming language
was derved from the
Sntish comedy series Interactive Modeis a
command line shell which gves
immediate result for each command.
"Monty Python's
Fying Grcus" IDLE stands for Integrated Development and Leaming
Environment
The input) function takes the user's input whille a program
executes.
The print0 function prints or sends the
outputto the
standard output device, which is usually a monitor.
ccording to a sunvey, Variables are memory reference points where we store
in the UK in 2015, values which can be accessed or changed later.
Python overtook A data type specifes the type of value a
variable can
ench to be the most contains.
opular language Comments enable us to understand
the way a
aught in primay works.
program
schools Operators can be defined as special symbols which perform
arithmetic and logical computation.
Arithmetic operatorsS perform arithmetic
between two operands operations
The assignment operators are used to assign the value of
the right expression to the left operand
n does not need
Relational operators are used to compare the value of
operands and returns True or False accordingly. the
Diler to execute two
program.
Precedence of operators determines the order in which the
operators are executed.
becomes true. X Y
Not
equalt checks if the values of two operands are TRUE
then
If the values are not equal,
equal or not.
thecondition becomes trud TRUE
ureater t checks if the value of left operand is B8reater >y
if yes, then
than than the value of right operand.
the condition becomes tru
of left operand is less x<y FALSE
Less than it checks if the value
t h a n the value of right operand. If yes, then
the condition becomes true is greater x >=y TRUE
if the value of left operand
Greater
t checks if
operand.
than or
than or equal to the value of right
equaltoyes, then the condition becomes true
left is less
the value of operand x<=y FALSE
Less than
it checks f
or equal to than or equal to the value of right operand. If
becomes true.
yes, then the condition
n of ans1gnmant operatot
b
a+b
)
nE
PELnt (o)
print
c / a
nt (o)
rint
print
PELRE (C
-
yight, oeit
A se"et
pe/hvyteta/lonsi/Beon/yn/ytn18/a*
tos
ataa
Logical Operators
Logicaleo p rators are used to
evaluate and
decide. Python
operatoraeDescription
supports the following logjcal operators
AND t
operands are Example (xa)
and returns true, if both
true. Output
(x5) and (x<10) TRUE
OR
It returns true, lt one of the
is true. operands x5) or (x<2) TRUE
not
NOT It reverses the result, returns
the result is true or vice false, if not [(x<5) and (x 10)) <
FALSE
versa.
progran 3: To perform all the logical operators.
b rala9
print and b)
pEint (not a)
print (not b)
Introduction to Programiming