Data Types
Data is information stored by the computer. In Python, we have many different types of data: strings, integers, floating numbers, boolean, and some others (that we won’t cover in this course). You can check the type of data of an object by using
type( )
. ( Make sure to put the object between the parentheses!)- Strings are a series of characters. Examples:
"I went to the store"
,"i"
,"12345"
, and"#^*&#)^&"
- Integers are normal numbers, like
-1
,0
,1
,2
,3
,100
. They can’t have any decimals.
- Floating numbers are decimal numbers:
1.2
,5.4
,2.6
,1.8
5.0
might look like an integer, but since there’s a decimal point, it’s a float, even if there’s nothing after the decimal point
- Booleans:
True
orFalse
(We’ll go deeper into booleans later in the course, for now just know that they exist)
Case matters in Python!
True
and False
are syntactically correct, while true
and false
are syntactically incorrect.Example code:
# strings are a series of characters # they are in single or double quotes print("Jane") print('Doe') # integers are whole numbers (positive, negative, and 0) print(25) # floating point numbers (floats) are numbers with decimals) print(16.54) # booleans are either true or false print(True) print(False)
View code on GitHub.
Next Section
2.2 VariablesCopyright © 2021 Code 4 Tomorrow. All rights reserved.
The code in this course is licensed under the MIT License.
If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.