1.0 DATA TYPES
In programming, data type is an important concept. Just as we discussed previously on variables, Variables can store different types.
Python has many built-in data types, such as
Text type : str
Numeric type : int, float, complex
Boolean type : True or False
Set
Sequence type : List, Tuple, Range
x = "Davis"
# x is a string data type
y = 4;
# y is an int data type
z = 7.5;
# z is a float type
To display the result of this, We make use of the print() built-in function;
print(x)
print(y)
print(z)
Output
Davis
4
7.5
Note:
We defined a var x = "Davis"; just as we have in other programming languages like Java, Python automatically detects the data type of the value)
Also, when declaring variable names, we take note of keywords, there are some reserved keywords in python that shouldn't be used as a variable name, some of such keywords includes return, is, continue, def, finally, and a few other words. Read further on Python keywords Click here for Python keywords
1.1 Checking the data type of the variable
It is important that we know how to check data types in Python, this is a basic concept that will come in handy when we get to more advanced topics like Data Preprocessing and Analysis.
We check the type of our data by using the type() method.
print(type(x))
print(type(y))
Output
int
str
Top comments (0)