Loading lesson...
Where every Python journey begins
Where every Python journey begins
Topics covered: How Computers Store Data, Variables and Naming, Assignment vs. Equality, Data Types and Strings, Operators and Readability
Before we can understand variables, we need to understand memory. Your computer has two main types of storage: When you run a Python program, it uses RAM to store all the data it needs. Think of RAM as a massive grid of tiny storage slots, each with a unique address (like a house number on a street). Each slot can hold a small piece of data. When you create a variable in Python, you're essentially telling the computer: "Reserve some of these memory slots for me, and let me refer to them by this
A variable is a named container for storing data in your computer's memory. The name "variable" comes from the fact that the value it holds can vary (change) during the program. The Labeled Box Analogy Imagine you have a warehouse full of boxes. Each box can hold something, and each box has a label on the front. The label is the variable name. The contents inside the box is the value. When you want to find something, you look for the label. When you want to change what's stored, you replace the
After this, score is 101. This would be nonsense in math (100 = 101?), but in programming it makes perfect sense: "Take the current value of score, add 1, store the result back in score." So How Do I Check Equality? Assignment stores a value: The first returns True ("Is x equal to 5?" Yes!). The second returns False. Using the correct operator in conditions: Confusing = with == is one of the most common beginner bugs. In Python, assignment always flows right to left: the value on the right is st
Every piece of data in your program has a type. The type determines what you can do with that data and how the computer stores it in memory. Think about the number "5" and the text "5". They look the same, but they're fundamentally different: They behave completely differently: The first gives 15 (mathematical addition). The second gives "510" (text concatenation). Trying text_five + 10 causes an error because you can't add text and a number directly. Data types exist because computers need to k
Python provides operators for mathematical calculations. Most work exactly like you'd expect from math class, but a few have special behaviors. Special Operators Python has three additional arithmetic operators that are incredibly useful: Floor division for whole numbers: 125 minutes = 2 complete hours. 45 items = 4 complete pages of 10. Modulo for remainders: Order of Operations Python follows the standard mathematical order of operations (PEMDAS): Parentheses, Exponents, Multiplication/Divisio