• In Python there are five types of data type that are used commonly and those are -
Values and Types
•
Data types are used to define type of variable.
•
In Python there are five types of data type that are used commonly and those
are -
Fig.
2.7.1 Data types in Python
•
int - holds signed integers of non-limited length.
•
long- holds long integers
•
float- holds floating precision numbers and it's accurate upto 15 decimal
places.
•
complex- holds complex numbers.
In
Python we need not to declare datatype while declaring a variable like C or
C++. We can simply just assign values in a variable. But if we want to see what
type of numerical value is it holding right now, we can use type(). For example
-
•
String is a collection of characters.
•
In Python, we can use single quote, double quote or triple quote to define a
string.
•We
can use two operators along with the string one is + and another is *.
•
The + operator is used to concatenate the two strings. While * operator is used
as a repetition operation. Following execution illustrates it -
•
It is similar to array in C or C++ but it can simultaneously hold different
types of data in list.
•
It is basically an ordered sequence of some data written using square
brackets([]) and commas(,)
For
example -
•
Tuple is a collection of elements and it is similar to the List. But the items
of the tuple are separated by comma and the elements are enclosed in ()
parenthesis.
•
Tuples are immutable or read-only. That means we can not modify the size of
tuple or we cannot change the value of items of the tuple.
•
Here are examples of tuples -
•
Dictionary is a collection of elements in the form of key:value pair.
•
The elements of dictionary are present in the curly brackets.
•
For example -
Problem Solving and Python Programming: UNIT II: Data Types, Expressions, Statements : Tag: Engineering Python : Python Programming - Values and Types
Problem Solving and Python Programming
GE3151 1st Semester | 2021 Regulation | 1st Semester Common to all Dept 2021 Regulation