Data Types in Python
In any programming language, the concept of data and datatype is very important. In this blog, we will have a brief look at all kinds of data types on Python and we will have a detailed discussion on each topic on upcoming Blogs.
Data Types in Python
Every value stored in the variable is treated as data whether it is x=5 or y="Nepal".Different kinds of data are used for doing different kinds of things. The following are the list of default data types in python.
- Text Type
- String(str)
- Numeric Types
- Integer(int)
- Float(float)
- Complex(complex)
- Sequence Type
- List
- Tuple
- Range
- Mapping Types
- Dictionary(dict)
- Boolean Type
- bool
We will discuss about each data type in further blogs.
#Getting the data types
If we are unknown about certain data type, we can get the data type by using type() function.
eg:
x = 5
print(type(x)) will give result as integer.
data = {"name" : "rafel", "age" : 34}
print(type(data)) will give result as dict.
#Setting specific data type
5 is integer and 20.5 is float of numeric data type but they can be made string of text data type by setting specific data type.
eg:
x=str(5) and y=str(20.5) will change 5 and 20.5 into string.
Comments
Post a Comment