Data Types Part 01¶
From our previous chapter, we learned about variables with a small primer on data types. In this chapter we will understand what they are and how we use them.
What are data types?¶
In Python, we can define a data type to be a concrete representation of any value. A value could be someone's name, money, age, or even a game boss's HP.
String Data Type¶
Let's take the example from our previous chapter:
From here, "Alan" is what we call the string data type. It is used to represent textual data
within its quotes ("). Python strings can use both double and single quotes, but the opening and
closing quote must match.
Examples of valid strings:
Examples of invalid strings:
Integer Data Type¶
Just like in mathematics, we have an integer data type in Python. An integer is a number that can be written without a fractional or decimal component.
Example:
Floating Point Data Type¶
Floating Point data type, more commonly called Float, is a data type representing decimal numbers.
Example:
Boolean Data Type¶
Boolean (or bool) is a special data type in Python. A boolean can only be one of two values: True
or False.
Example:
Warning
True and False are case sensitive. true is not the same as True.
Booleans are more commonly used in conditional statements, loops and comparison operators which we will learn in later chapters as a continuation.