<jupyter_start><jupyter_text>2. Basic data types and variables  To computers, everything is a number (or a bunch of numbers)As far as computers are concerned, everything is a number or a bunch of numbers:* **Code:** Just a bunch of numbers, which the computer interprets as instructions to manipulate other numbers.* **Data:** Just a bunch of numbers. In fact, the computer only distinguishes code and data through context. Think of this distinction as being like a cookbook. If you’re reading it for fun, it’s data. If you’re following a recipe in the book, it’s code.Unlike computers, we think of data as having different forms. To allow computers to understand us, and us to understand their output, most programming languages have a concept called **data types**, which are used to represent different forms of data. Data types Number data typesIn order to perform math and counting operations, we have data types that represent numbers. They come in the following flavors:* **Integers,** which represent whole numbers, both positive and negative. -5, 0, 5, and 5000 are all examples of integers. The Python term for integer is `int`.* **Floating-point numbers,** which represent the “real” numbers — that is, numbers with fractional parts or decimal points, both positive and negative. -5.2, 0.0. 5.567891234, and 5020.492492 are all examples of floating-point numbers. The Python term for floating-point number is `float`.Try the following code in either the Python interpreter or a Jupyter notebook:<jupyter_code>type(2)
type(2.5)<jupyter_output><empty_output><jupyter_text>`type` is a function that takes the value you give to it — the *argument* — and it gives you back, or *returns* a result indicating the argument’s data type.In the examples above, `type` says that 2 is an `int` (integer) and that 2.5 is a `float` (floating-point number). Working with numbersYou may have already guessed that you can perform math operations on number types. Here’s a handy table of Python *arithmetic operators*:            Operator        Notes                +                    Addition                        - or &lt;&gt;                    Subtraction                        *                    Multiplication                        /                    Division                        %                    Modulus            a % b returns the remainder of the division of a by b.                        //                    Floor division (a.k.a. integer division)            Like division, except the result is *floored* — rounded down to the nearest integer. Some examples:                            10 // 3 returns a result of 3. 10 divided by 3 gives a result of 3.333..., and 3.333... when floored (rounded down to the nearest integer) becomes 3.                9 // 3` returns a result of 3.                10 // -3 and -10 // 3 both return a result of -4`. 10 divided by -3 and -10 divided by 3 both give a result of -3.333..., and -3.333... when floored (rounded down to the nearest integer) becomes -4.                                    **                    Exponentiation            a ** b returns a raised to the power of b.              String: The data type for textIn order to perform operations on text, we have the **string** data type. It’s called “string” because it refers to a string of characters — that is, a set of zero or more characters with a specific sequence.String values are enclosed in quotes — either single quotes (`' '`) or double quotes (`" "`). The following are examples of strings:* `'a'`: A single character.* `"book"`: Multiple characters.* `'25'`: One or more digits. Since it’s inside quotes, it’s not a number, but a string that just happens to be made of the numbers 2 and 5. You can’t do math on it.* `""`: The empty string — a string containing no characters. This represents things like the value inside a text field that hasn’t been filled out yet.Try the following code in either the Python interpreter or a Jupyter notebook:<jupyter_code>type('a')
type("book")
type('')<jupyter_output><empty_output><jupyter_text>In the examples above, `type` says that `'a'`, `"book"`, and `''` all are of type `str` (string).You can’t do math operations on strings, but you can perform *string operations* on them, such as counting how many characters they contain, converting them to all uppercase, all lowercase, or “titlecase”, or joining them together to form incredibly long words, just like they do in the German language. Working with stringsThis is a big enough topic that it’ll get its own chapter (the next one).  Boolean: The data type for `True` and `False` values, and decision-makingA key part of programming is decision making, which involves determining if some condition or set of conditions has been met. This calls for a data type that can specify whether something is true or false, and that’s what the **Boolean** data type is for. It’s called Boolean after mathematician, logician, and philosopher [<NAME>](https://en.wikipedia.org/wiki/George_Boole), who created [Boolean algebra](https://en.wikipedia.org/wiki/Boolean_algebra), the branch of algebra in which the values of the variables are the truth values true and false (which are usually denoted 1 and 0, respectively).There are only two possible values for Boolean data:* `True`* `False`Note that both are capitalized.Enter the following in either the Python interpreter or a Jupyter notebook:<jupyter_code>2 > 1<jupyter_output><empty_output><jupyter_text>Python interpreted the above as an expression — a line of code that results in a value — and evaluated that value. Since 2 is indeed greater than 1, it returns the value `True`.Now enter this:<jupyter_code>2 < 1<jupyter_output><empty_output><jupyter_text>Once again, Python considers what you entered an expression and evaluated its value. 2 is not less than 1, and therefore Python returned the value `False`.Enter this:<jupyter_code>1 == 1<jupyter_output><empty_output><jupyter_text>In Python and many other computer programming languages, `==` — two equals signs in a row — is used to test if two values are equivalent.The single equals sign, `=`, is used to assign a value to a *variable*. For instance, the code below says the variable `x` is assigned the value 5:```x = 5```On the other hand, the code below is used to test if the value contained in `x` is equal to 5:```x == 5```So remember:* `=` is used to assign values to variables.* `==` is used to compare two values to see if they’re equal.Here’s a handy table of Python *comparison operators* (also known as *relational operators*):            Operator        Notes                ==                    “Is equal to”            a == b is True if a and b are equal.                        != or &lt;&gt;                    “Is not equal to”            a != b and a &lt;&gt; b are True if a and b are not equal.                        &lt;                    “Is less than”            a &lt; b is True if a is less than b.                        &lt;=                    “Is less than or equal to”            a &lt;= b is True if a is less than or equal to b.                        &gt;                    “Is greater than”            a &gt; b is True if a is greater than b.                        &gt;=                    “Is greater than or equal to”            a &gt;= b is True if a is greater than or equal to b.<jupyter_code>type(2 > 1)
type(2 < 1)
type(2 == 1)<jupyter_output><empty_output><jupyter_text>In the examples above, `type` says that `2 > 1`, `2 < 1`, and `2 == 1` all are of type `bool` (Boolean).  VariablesIn computer programs -- Python programs included -- **variables** hold information that will be used and processed. They're also a way to label that information with a descriptive name, so the program can more easily be understood by programmers.Think of variables as boxes or containers that hold data. Once you put data into a variable, you can use that data in your program. Variables in actionHere’s an example of variables in action:<jupyter_code>score = 5
print("Here's the score:")
print(score)
bonus_multiplier = 1.2
score = score * bonus_multiplier
message = "Here's the updated score with the bonus multiplier applied:"
print(message)
print(score)<jupyter_output>Here's the score:
5
Here's the updated score with the bonus multiplier applied:
6.0
{'fraction_non_alphanumeric': 0.07649813858532485, 'fraction_numerical': 0.01405067851567191, 'mean_word_length': 2.956294536817102, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '356969', 'license': 'MIT', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2034, 'n_words': 1176, 'path': '2. Basic data types and variables.ipynb', 'repo_name': 'AccordionGuy/Intro-to-Python-2020', 'size': '8333'}