# Data Types

{% embed url="<https://www.youtube.com/embed/Qnmswnu0BSA>" %}

&#x20;[Basics](http://python.swaroopch.com/basics.html)

## Data Types

A data type is simply the type of data we can store in programs. Python has a fairly small set of data types.

* integer (int) which are numbers like `1`, `4`, `7`
* floating point (float) which are numbers like `3.5`, `6.2`, `8.9`
* string (str) which is simply a collection of characters (any character you

  &#x20; wish like: `askj#@lk14p`) surrounded by quotes (' or ")
* boolean (bool) which can be either `True` or `False` (see \[George

  &#x20;  Boole]\(<https://en.wikipedia.org/wiki/George_Boole>)). `True` and `False` are

  &#x20;  special words in Python and are reserved for their raw values. That means

  &#x20;  that you may not use them when naming things.

## Operators

You can manipulate data using operators (+, -, \*, /, <, >, etc). The obvious math operations like `1+2` work but we also have other operations like `'I like ' + 'britney'`. This operation will concatenate (or combine) the two strings into a single string.

Try printing out to the terminal screen some math operations:

```python
# use the exponentiation operator
print(2**3)
print('reed likes' + ' to program')
```

Running this program should produce: `8` and `reed likes to program`.

In addition to the math operators and a few that work on strings there are also a number of booleans operators (<, >, <=,

> \=, ==, !=, not, or, and).

```python
print(3 < 4)
print('4' != 4)  # strings are never equal to numbers
print(42 == 42)
print(1 < 2 and 2 < 3)
```

Running this program should produce: `True` 4 times.

&#x20;*Try printing out some expressions using various operators!*

## Variables

Variables are simply a way to keep track of the values you want to manipulate. They act as boxes to hold data types. You can create a variable by doing the following:

```python
my_name = 'reed'
my_height = 70.9375
happy = True
```

The first variable will hold a string with the value of `reed`, the second will hold an floating point with the value of `70.9375`, and the third will hold a boolean with the value of `True`.

Variable names have specific rules. They have to be a single word (no spaces) and can have numbers, letters or underscores. They cannot begin with a number and are case sensitive (meaning `SPAM` does not equal `spam`).

&#x20;*Try storing the results of your previous operations in variables. Then print them out!*

## Tip

You can combine strings (concatenate) using the `+` operator but this gets pretty inefficient if you do it in loops (which we will learn about in a later lesson). It is always a good idea to combine strings using string formatting. You can create a string that has special tokens inside of it and then replace those tokens with the values you supply.

```python
name = 'reed'
height = 72
eye_color = 'blue'
print("Hello! My name is %s. I am %d inches tall and have %s eyes".format(name, height, eye_color))
```

Doing this will be more efficient and ends up being more readable in my opinion. One thing to keep in mind though is that if you have a decimal number (like `height` in the example), you need to use a `%d` instead of a `%s`. For a list of format characters and what they mean check out the [Python documentation](https://docs.python.org/2.4/lib/typesseq-strings.html). [Dive Into Python](http://www.diveintopython.net/native_data_types/formatting_strings.html) also has a really great article that goes into greater detail.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://programming.reedcwilson.com/lesson-1/data-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
