Python Program Element - Variable
Python Program Element - Variable
0 PYTHON PROGRAM
ELEMENT
DFP4022 PYTHON PROGRAMMING
Variables and Data Types
in Python
2.1 Discover common
programming element using
Python
Variables in Python
Python is completely object oriented, and not "statically typed".
Python variable do not need to declare the variables and data type.
The declaration happens automatically when assigning a value to a
variable. The equal sign (=) is used to assign values to variables.
Examples : y = 1+2
name = “Aliah”
The operand to the left of the = operator is the name of the variable and
the operand to the right of the = operator is the value stored in the
variable
Every variable in Python is an object.
Variables reserved memory locations to store values. Some space in
memory is reserved when creating a variable.
Based on the data type of a variable, the interpreter allocates memory
and decides what can be stored in the reserved memory.
Data Types in Python
Numbers
Strings
Lists
Dictionaries
Tuples
Sets
Data Types in Python
Data Description
Type
Numbers Number data types store numeric values. Integers, floating
point numbers and complex numbers fall under python
numbers category. They are defined as int , float and
complex classes in python.
Strings Strings is sequence of Unicode characters. We can use single
quotes or double quotes to represent strings. Multi-line
strings can be denoted using triple quotes
Lists Lists is an ordered sequence of items. It is one of the most
used data type in Python and is very flexible. All the items in
a list do not need to be of the same type. Lists are defined
zero-based indexed by declared using brackets [].
Dictionari Dictionaries are the most flexible built-in data type in
es python. Dictionaries items are stored and fetched by using
Data Types in Python
Data Description
Type
Tuples A tuple is a sequence of Python objects separated by
commas. Tuples are immutable, which means tuples once
created cannot be modified. Tuples are defined using
parentheses ().
Sets A set is an unordered collection of items. Set is defined by
values separated by a comma inside braces { }.
Mutable and Immutable
Data Types in Python
Mutable object can be changed after it is
created, and an immutable object can’t be
changed.
Mutable data types in Python are list,