Adobe Scan Feb 20, 2025
Adobe Scan Feb 20, 2025
athoncomes in three versions: version 1.0, version 20 and version 30 Many series are
nlable
in
these
versions. In this chapter,
we are using
and go to the version 3.10
The following
foll
official website https //www python og/downloads/ and press
page appears in your
Fnter
key
browser
Python
1 Click on Download
3.10.5.
PPython Doate
wnoe
NSTALLING PYTHON
downloading, next step is to install it in your computer.
1. Open Downloads folder and double-click
on Python program icon
Installation process starts and Python Setup
dialog box appears
Setup Progress
’ Customize instsllatson
Chensr lacun and feures
ngtaling
ingljndher for# uers (reomnended
Pthon 105 s Sert 4 b
CAdd Pthon310 to PATH
IT
PLANET
121
GETTING STARTED WITH PYTHON
WriteCode in Interactive Mode window:
will getthis
Afier installing, when you open Python, you
X
A DLShel 105
1929 64 b
: 13) (MSC v.
(le Ldit Shell Debuo
Options Window Help
Jun 6 2022, 16:14
10.5:f37 7153,
Tytho 310.5 (tags/v3. information.
1 (AMD64)| on win32 "redits" or "license () " for more
"copyj ght ".,
Vpe "he lp",
mode.
Python" at the prompt and press Enter key.
Let us enter a statement "Welcome to
>> print ("Welcome to Python")
PM The prompt (>>>) reappears to tell you that the Python shell is ready to accept more comman0.
In the above program, the print() is a type of Python command called afunction, and it pe
out whatever is inside the quotes to the screen.
122 Great! You have just created your first Python program.
keywords are:
Me
of the
True False
None and
assert def class
Contintue break
else finally elif del
ecept
global for if
from import
raise try return pass
nonlocal in not
lambda
ITERALS
data
Items that never change their value throughout the prograrm run are called literals
the
heoretically,literal means any number, text or other any informat1on that represents a value
supportsthe following literals:
ython
Literals Examples
Stringliterals "hello", '12345'
integerliterals 0, 1, 2, -1, -2
Floating-point literals 3.14, 2.05
Boolean literals True or False
OPERATORS
arithmetic and iogical computations The values
Onerators are the special symbols that carry out
are many types of operaiurs in Python like
nnerated by the operator are called operands. There
this chapter, we will learn about Arithmetic
Arithmetic, Relational, Logical, Assignments, etc. In
operators.
ARITHMETICOPERATORS
mathematical operations.
Arthmetic operators are used to perform
Example
Operator Meaning >>> 200+45
Addition and Concatenation in Strings
245
>>> "Good' + "+"Morning
Good Morning
>>> 100-20
Subtraction
80
>>> 80-160
80
Replication in Strings 20
Multiplication and
ovthonvthonov
>>> 284
70
Division
>>> 50/5
33333B4
>>> 20//4
Floor Division/Integer Division
>>> 50/6
>>> 679%9
% Modulus/Remainder
>>> 8**2
Exponentiation 64
Comments
in any language. Thev are used to exD3
Comments are very important while writing a program
interpreter ignores the text written in
Python code and make it more readable. Python
comment. Python supports the following comments in a program.
SINGLE LINE COMMENTS
Python uses hash symbol (#) for writing a single line comment.
Examples:
>>> #This is the start of program This is a single line comment
>>> #print hello in Python This is a single line comment
>>> print ("Hello") This is a statement
TILINE
COMMENTS
USestriple quotes or
for multi-line comments.
example of
is an
" This
multi-linecomments"
satements
statement0S an instruction that the Python interpreter can execute. When
atementonthe IDLE, Python executes it and displays the result. you type o
pata Types
used to define the type of value a data can contain. It represents what kind of
Datatype IS
peration can be done on a particular data. Data types define the way to store values in the
memory.
NTEGER
without decimal point such as 1000,
ntegers are the whole numbers consisting of + or - sign
8, etc.
ELOAT
example,
represents floating point numbers which contain decimal point. For
iOat data type
05, -4.567, 0.001, etc.
This is a float value
>>> a=12.5 #
Example: integer value
>>> b=12 # This is an
print (num2 )
103
in this example, we are telling Python that we want the variable num2 to initialize the s.
value as num1 by using the assignment operator (=) between num2 and num1.
You can also write variables like total_marks.
>>> total marks =
500
>>> print (total marks)
500
print(String/
/Variable/Constant)
Output
User input
.e Purple color shows Functian nome Green color shows the Stting Blue
shows the Output and Black color shows the Vargble gnd Use npu
le Edit Format Run Options Window Help 1 Create a new file in Python
Script Mode
me=input ("Enter your Name:") 2 Type the given code
age=input ("Enter your Age:") 3 Save and Run the module
pILnt (name) By default IDLE saves the Python iie
pIint (age) with .py extensIon
cKinB on Run module, interactive mode appears with the pre-input text Enter your Name
Akash Now, next pre input text Enter your Age appears
13 6 Type your age
7 Press the Enter key
the output
print() function shows the entered name and age as
using int() function
two numbersconverts
Program2 sum of the entered value into
printthe function
Program to input() function. but could not use for the
As
discussed
only be
used
earlier, the print()
to print
using
with an
example. calculation purstrpinose.B, which coua
it
understand Mode Output in
Enter Interactive
in Script
Let us Source Code e
Window Help
Qptions Enter First Mode
Eile Edit
numl=input
format Bun Flrst Nmber ")
("Enter
ter
Number ")
Second
2030 Second Nunber
Nunbe 20 r
30
nun2=input ("n
sum=num1+num2
print(sum)
of 20 and 30 shows 2030 as
the sum
operator concatenatesthe
code,
the source function and the 4'
When you run
converted into string
using
calculation
input()
between these
value, vou need to convert the
(ienteorediginvs)enbotvalhuevalugete:
Now, to show
into integer
function.
using int() string value:
Using Int()
Source Code in Script
Mode Output in Interactive Mode
Options Window Help Enter First Number 20
|Eile Edit Format Run Enter Second Number 30
First Number "))
num1=int (input ("Enter 50
Second Nmber "))
num2=int (input ("Enter
sum=num1 +num2
print (sum)
in the above program, when you run the source code, the Sum of 20 and 30 shows 50 28 the
given value converts into integer using int() function so operator performs the additn
between entered values.
Note: You can also convert string into decimal value, using float() function.
LTD.
PVT.
Self-Evaluation ABree isagree
CHECKLIST
Disag,
After
PUBLISHERS reading the chapter, I know these points:
Tknow that token is the smallest element of a program that is meaningtul to the
interpreter.
I know
W that
operators are special symbols that carry
computations. out arithmetic and logical
I know
that data types
Iknow that
define the type of value a data can
variables are used to store contain.
Iknow that data in the
input() and print() memory.
functions
are used to get input and display output.
EXercises
the correct
(1
fick
answer.
python keywords contain
Al/
2. Operator:
3. Comments:
identifier?
you mean by
2. What do
variables?
3. What are
?
understand by line and indentation
4. What do you
G. Answer briefly.
Explain in detail.
1. Howmany data types are used in Python?
Group Discussion
Divide the students into two Function for
Calculation'. groups and discuss the topic - 'Importance of int/)
Online Link
To learn more about
Python programming, visit the website: