0% found this document useful (0 votes)
10 views

Variables and Types

Different variable types in Python include numbers, sequences, mappings, and booleans. Variables can be mutable or immutable. Python supports various statements like print, input, import, and form to output text, accept user input, incorporate external code, and select specific functions from modules. User-defined functions allow programmers to create their own reusable blocks of code.

Uploaded by

Yash Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Variables and Types

Different variable types in Python include numbers, sequences, mappings, and booleans. Variables can be mutable or immutable. Python supports various statements like print, input, import, and form to output text, accept user input, incorporate external code, and select specific functions from modules. User-defined functions allow programmers to create their own reusable blocks of code.

Uploaded by

Yash Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Different types of variable used in

python
Every object has:
Creating a program A. An identity which can be
often requires storing known using an is
(object)
values as we may use it
B. A type which can be
later. Objects capture checked using the type
(object) and
the data, which can
C. A value
then be manipulated by
• Identity of the object:
the computer to furnish This defines the address
of the object in memory
information.
and is immutable once
created.
• Type : This denotes a set
of values and the
operations possible on
them.
Number
This kind of data type can store numerical and is immutable,
which means that the value of its object remains unchanged.

Example : >>>mark = True


>>>type(mark)
<type ‘bool’>

Sequence
An arranged group of items that are indexed by
positive integers is known as a Sequence.

Example: >>> a= 23.78


>>> b= int(a)
>>> print b
23
Mapping
This data type is unordered and mutable.

Example: d = {1:’x’, 2:’y’, 3:’z’}

• Value of object (variable) – binding of a value to a


variable is done by assignment operator (=). This is
also known as building of a variable.
Operator (=). This is also known as building of a variable.

Mutable and Immutable Variables


A mutable variable has a value that can be changed in
place. On the contrary, the immutable variable can never
be modified doing so will reconstruct the same variable.

Example: >>>a=8
Will create a value 8 referenced by a
a 8
Different types of Statements used in
python

Print Statement
Print computes the expression before generating it as
output to the monitor. It sequentially processes one
line for output before moving to the next. To print more
than one item on a single line, comma (,) may be used.
Example: >>>print “Hello”
Hello
>>>print 9+1
20
>>>print 41.176
41.176
Input Statement
The data that the end user types into the program is called input.

Example: >>>x=raw_input (“Your favourite car is: “ ”)


Your favourite car is: ABC

Import Statement
It is possibly the easiest and popular way of using modules in our code.
Example: >>>import math

When this statement completes execution, Python will


i. Search for the file “math.py”
ii. Make space available where module definition & variable will be constructed,
iii. Then execute the statements in the module.
In this way, the definition of the module will be utilised by the code which imported the module.
Form Statement
When we require only a specific function in the code instead of the
complete module file, we use the form statement.

Example: >>>form math import sqrt


value= sqrt (441)

User defined function


The programmer may choose to construct his own function (s). These
then can be collectively formed as a module which can, in turn, be
imported by other programs.
To define a function, keyword def is used. After the keyword comes an
identifier, i.e., the name of the function, followed by the parenthesized
list of parameters and the colon which ends up the line.

Example: def sum(a,b):


total = a + b
return total
x = 10
y = 20
print("The sum of",x,"and",y,"is:",sum(x, y))
THANK YOU

Name - Yash Jain


Class - VIII – C
Roll No. - 55

You might also like