Python Lesson 2: Data Types
Data types are categories of data in Python. There are 4 main date types: integers, floats, strings, and boolean values.
First up, integers. These are simple enough- an integer is just any number without a decimal point. These can be positive or negative. 5, -2, 9, and 16 are examples of integers. The name integer
is written as int
in Python.
Next, we have floats. Floats are any number with a decimal point. So, while in our above example, 5, -2, 9, and 16 are integers, if we instead changed them to be 5.3, -2.0, 9.6, and 16.4, they would instead become floats. Notice how although -2.0 is technically just -2, it is still considered a float. Python takes floats very literally, so if there is a decimal value within a number, it doesn't care what that value is- it'll be a float regardless.
Next, we have strings. Strings are any line of text and are marked with either single (') or double (") quotation marks. It's best to think of strings as writing a quote- you need the quotation marks to show that it's something you want spoken. An example of a string would be 'Hello' or "Hello". The name "string" is shortened to "str" in Python.
Lastly, we have boolean values. Booleans have two values: true and false. The name "boolean" is shortened to "bool" in Python. When using boolean values, you must always type "True" or "False" with a capital first letter.
Lesson Recap:
- Integers, floats, strings, and boolean values are all data types in Python. Each one serves a specific function.
- Integers are written as "int" in Python. Integers are numbers without a decimal point.
- Floats are written as "float" in Python. Floats are numbers with a decimal point.
- Strings are written as "str" in Python. Strings are text which must be surrounded by single or double quotation marks.
- Boolean values are written as "bool" in Python. The two boolean values are True and False.
In the next lesson, we'll look at the basics of functions.