Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

XII Python Revision tour-II

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Data Types in Python

 Data Type represent types of data or values , a variables can hold.


for Example:- a=10 # represents int
f=10.0 # represents float
 In python, we are not required to mention any type explicitly, based on your provided valued automatically
type will considered, such type is called dynamically typed programming language.
 Data types are used to stored the data temporarily in our computer through program.
 We have following types of data types in python.
int
float
complex
bool
str
list
tuple
set
frozenset
dict
bytes
bytearray
range
None
 In python, everything will be object, for example:-integer, decimal value, and Boolean value all are object
Example
a=10
type(a)# type is an python inbuild function
id(a)# id is python build function

type():- returns the type of variable or object a variable nhold.


a=10
print(type(a),a)#int,10

id():- returns the address of those values. If you are supposed to change the value, address will also changed

a=10
print(id(a))
print(a)
a=20
print(b)
print(id(b))
Variable:
A variable is a label for a location in memory. It can be used to hold a value.
In statically typed languages, variables have predetermined types, and a variable can only
be used to hold values of that type. In Python, we may reuse the same variable to store
values of any type.

Defining variables

To define a new variable in Python, we simply assign a value to a label. For example, this
is how we create a variable called COUNT, which contains an integer value of zero
count = 0

LValues : These are the objects to which you can assign a value or expression. LValues can come on
lhs or rhs of an assignment statement.
RValues : These are the literals and expressions that are assigned to LValues.
e.g. a = 20
b = 10
a and b are LValues , whereas 20 and 10 are RValues.

MULTIPLE ASSIGMENT
1. Assigning same value to multiple variables
You can assign same value to multiple variables in a single statement, e.g.
a = b = c = 10
It will assign value 10 to all three variables a, b, c.

2. Assigning multiple values to multiple variables


You can even assign multiple values to multiple variables in single statement, e.g.
x, y , z = 10 , 20 , 30
It will assign the values order wise, i.e., first variable is given first value, second variable the
second value and so on. That means, above statement will assign value 10 to x , 20 to y and 30 to
z.

You might also like