Introduction to Python Data Types

Published on July 29, 2017 by

So far, we have only been dealing with printing out and storing text. In Python, text is of the type str, short for string.

In addition to text, Python supports several other data types such as bool, int, and float. The bool data type — short for boolean — is exactly like a light bulb, and is often referred to as a flag as well. Just like a light bulb can either be on or off, a boolean value can either be True or False. The int data type is used for integers (i.e. whole numbers), and the float data type is used for numbers with decimal points.

In the previous post, you learned the basics of variables in Python. A variable can contain not only text, but also values of the int, float, and bool data types. There are more data types than these, which we will get back to later in the tutorial.

Consider the following lines of code.

variable1 = 5
variable2 = 4.5
variable3 = True

The first line creates a new variable named variable1 and assigns it the integer value 5. The second line creates a variable named variable2 and assigns it the floating point value 4.5. Similarly, the third line creates variable3 and assigns it the boolean value True.

These are the basic primitive data types in Python. Like I mentioned, there are more data types, which we will look at as we go along and gradually expand our knowledge about Python.

Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

Leave a Reply

Your e-mail address will not be published.