DEV Community

Davisonyeas
Davisonyeas

Posted on

Getting Started With Python PyStart(Data Types)

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

  1. Text type : str

  2. Numeric type : int, float, complex

  3. Boolean type : True or False

  4. Set

  5. Sequence type : List, Tuple, Range

Image description

x = "Davis"
# x is a string data type
Enter fullscreen mode Exit fullscreen mode
y = 4; 
# y is an int data type
Enter fullscreen mode Exit fullscreen mode
z = 7.5;
# z is a float type
Enter fullscreen mode Exit fullscreen mode

To display the result of this, We make use of the print() built-in function;

print(x)
Enter fullscreen mode Exit fullscreen mode
print(y)
Enter fullscreen mode Exit fullscreen mode
print(z)
Enter fullscreen mode Exit fullscreen mode

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))
Enter fullscreen mode Exit fullscreen mode
print(type(y))
Enter fullscreen mode Exit fullscreen mode

Output
int
str

Top comments (0)