Advertisement
Type Category | Data Type | Description |
---|---|---|
Numbers |
int | Used to represent integer numbers |
Numbers |
float | Used to represent floating-point numbers |
Numbers |
complex | Used to represent complex numbers |
Numbers |
bool | Used to represent boolean values - True or False |
#Python - An example of values under the Number type category
# Creating an integer object of type int
x = 9
print(x, 'is of type', type(x))
# Creating an floating-point object of type float
y = 19.99
print(y, 'is of type', type(y))
# Creating an complex number object of type complex
z = 9+2j
print(z, 'is of type', type(z))
# Creating an boolean object of type bool
b = True
print(b, 'is of type', type(b))
9 is of type <class 'int'>
19.99 is of type <class 'float'>
(9+2j) is of type <class 'complex'>
True is of type <class 'bool'>
Advertisement
Type Category | Data Type | Description |
---|---|---|
Sequences |
str | Used to represent strings |
Sequences |
list | Used to represent a mutable ordered sequence of items |
Sequences |
tuple | Used to represent an immutable ordered sequence of items |
#Python - An example of values under Sequences type category
# Creating an string object of type str
s = 'Hello World!'
print(s, 'is of type', type(s))
# Creating an list object of type list
misc =[19 ,-9, 9.99, 'Have a perfect day!']
print(misc, 'is of type', type(misc))
# Creating a tuple object of type tuple
customer =('Edward', 27, 178.5, 'M')
print(customer, 'is of type', type(customer))
Hello World! is of type <class 'str'>
[19, -9, 9.99, 'Have a perfect day!'] is of type <class 'list'>
('Edward', 27, 178.5, 'M') is of type <class 'tuple'>
Type Category | Data Type | Description |
---|---|---|
Mapping Sets |
dict | It is used to represent sequence of items stored in the form of key:value pairs, where key and value are objects. |
Mapping Sets |
set | It is used to represents an unordered sequence of items. |
#Python - An example of values under Mapping Set type category
# Creating an dict object with key-value pairs of type dict
dict1 = {
4:'Fourth',
3:'Third',
'two':'Second',
'one':'First',
5:'Fifth'
}
print(dict1, 'is of type', type(dict1))
# Creating an set object of type set
set_ex ={'Never give up', 19.2, -29, 'A'}
print(set_ex, 'is of type', type(set_ex))
{4: 'Fourth', 3: 'Third', 'two': 'Second', 'one': 'First', 5: 'Fifth'} is of type <class 'dict'>
{'A', 19.2, 'Never give up', -29} is of type <class 'set'><class 'tuple'>
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement