Variables in Python

A variable is a place to store things. In Python, variables are given a name, and can store different types of things. Below are some examples.

Don't worry about understanding everything at this point; there will be examples later.

Number

number_of_pets = 3

String

A string helps you store text.

dog_name = "spot"

Boolean

A boolean is a true or false value.

is_favorite_fruit = True;

List

favorite_fruits = ["banana", "apple", "pear"]

Tuple

A tuple is a read-only list; you can't add or remove items.

favorite_fruits = ("banana", "apple", "pear")

Dictionary

letters_to_words = {
    "a": "apple",
    "b": "boy",
    "c": "car"
}

Variables can also store functions and objects (we'll talk about these soon).

Next: Numbers in Python

Comments

Leave a comment

What color are brown eyes? (spam prevention)
Submit
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.