Python -Data Types
Every programming language has different data types to hold data during program execution and it falls into different categories like numeric, string, list and dictionaries. Python is a dynamically typed language. It can hold different data types in the same program.
Python data types are categorized into four important categories.
1-Numeric Type
2-Sequence Type
3-Boolean Type
4-Dictionary Type
1-Numeric Data Type
In the numeric data type, the python variable holds the int and float numeric values like the below declaration.
Python supports 4 different types of numerical data.
- int (signed integers like 67, 78, 788, etc.)
- long (long integers used for a higher range of values like 809090900L etc.)
- float (float is used to store floating-point numbers like 7.9, 8.9, 895.2, etc.)
- complex (complex numbers like 8.14j, 9.0 + 8.3j, etc.)
Example:
Int data type declaration
a=34
Float data type declaration
b=34.45
2-Sequence Type
In the sequence data type, the python variable holds the list and strings values like the below declaration.
String
The python string data type can be defined as the sequence of characters represented in the quotation marks. It can be a single or double quote.
Example:
String data type declaration
a="Hello World !"
List
Lists are similar to arrays. But the list can contain different types of data.
Example:
List data type declaration
b=[1,2,3,4,5,6,7,8]
3-Boolean Type
Python boolean data type can contain only two values either True or False
Example:
Boolean data type declaration
test=True
test1=False
4-Dictionary Type
Python Dictionary is an ordered set of a key-value pair of items. It is like an associative array or a hash table like other programming languages where each key stores a specific value.
Example:
Boolean data type declaration
data = {1:'Test1', 2:'Test2', 3:'Test3', 4:'Test4'};
print("1st name is "+data[1]);
print("2nd name is "+ data[4]);
print (data);
print (data.keys());
print (data.values());