4.1.2. Basic Data Types# First, we’ll look at a few basic data storage types. We’ll also be including some code examples you can look at, though don’t worry yet if you don’t understand the code, since we’ll be covering these in more detail throughout the rest of the book. Booleans (True / False)# Binary consisting of 0s and 1s make it easy to represent true and false values, where 1 often represents true and 0 represents false. Most programming languages have built-in ways of representing True and False values. Fig. 4.4 A blue checkmark is something an account either has or doesn’t so it can be stored as a binary value.# Booleans are often created when doing sort of comparison or test, like: Do I have enough money in my wallet to pay for the item? Does this tweet start with “hello” (meaning it is a greeting)? Click to see example Python code # Save a boolean value in a variable called does_user_have_blue_checkmark does_user_have_blue_checkmark = True # Save a boolean value in a variable based on a comparison. # The code checks if a wallet has more in it than the cost of the item # which will be True or False, and be saved in has_enough_money has_enough_money = money_in_wallet > cost_of_item # Save a boolean value in a variable based on a function call. # The code checks if the text of a tweet (stored in tweet_text) starts # with "Hello", which will be True or False, and be saved in is_greeting is_greeting = tweet_text.starts_with("Hello") Copy to clipboard Numbers# Numbers are normally stored in two different ways: Integer: whole numbers like 5, 37, -10, and 0 Floating point numbers: these can represent decimals like: 0.75, -1.333, and 3 x 10 ^ 8 Fig. 4.5 The number of replies, retweets, and likes can be represented as integer numbers (197.8K can be stored as a whole number like 197,800).
This section helped me clearly see how different data types represent different kinds of information. Booleans are especially interesting because they force complex situations into true/false decisions, which can oversimplify reality. It also made me realize how choices about numbers and strings affect what computers can accurately store and how much meaning might be lost through rounding or categorization.