Python Foundations: Beginner
Dropbox stored over one billion files in its first three years, and its entire backend pipeline for syncing, deduplication, and conflict resolution is built on Python, the same language you are about to start learning. When Dropbox engineers need to track a user's file metadata or format a notification about a shared folder update, they reach for the same variables and print statements covered in this lesson. Python's creator designed it to read almost like plain English, which is why a small team was able to build Dropbox's core infrastructure quickly without switching to a more complex language. The concepts you learn here, variables, data types, and basic output, are the atoms that every Python program is built from.
Variables and Assignment
Store and reuse values in your code
Creating Variables
> You want to store the number 10 in a variable called x. Pick the correct operator to assign the value.
x 10 print(x)
Data Types
Work with numbers, text, and booleans
Core Built-in Types
> Every value in Python has a type. Pick different values to discover what type Python assigns to each one.
x = print(type(x))
Python can convert between types using built-in functions. int("42") converts a string to an integer, and str(42) converts an integer to a string.
Booleans are a subtype of integers in Python. True equals 1 and False equals 0, which means you can use them directly in arithmetic expressions.
Print Statements
Display output from your programs
Basic Output
The print() function displays output to the console. You can print simple text, variables, or formatted strings.
F-Strings for Formatting
> Build a formatted string that embeds variables. Choose the string prefix that enables variable interpolation, and the variable that holds the person's name.
name = "Alex" age = 25 print("Name: {name}, Age: {age}")
You can change the separator between printed values using the sep argument, and suppress the trailing newline with end="".
> This print statement runs but has unnecessary double parentheses. Remove the extra tile to clean it up.
Code runs but has unnecessary double parentheses
Basic Operators
Do math and combine values in code
Arithmetic Operators
> You have two numbers: 10 and 3. Pick an arithmetic operator to compute a result.
result = 10 3 print(result)
Comparison Operators
Comparison operators compare two values and return a boolean (True or False). These are essential for conditional logic.
> Calculate sales tax and the total price. Choose the right arithmetic operator for each step: one to compute the tax amount, and one to combine price and tax.
price = 10 tax = price 0.08 total = price tax print(total)
Python also provides floor division (//) and modulo (%) operators. Floor division returns the integer part of the quotient, and modulo returns the remainder.
Augmented assignment operators like += and *= update a variable in place. Writing count += 1 is equivalent to count = count + 1 but more concise.
Comments
Document your code for future readers
Single-Line Comments
Single-line comments start with #. Everything after the hash symbol on that line is ignored by Python. You can use them on their own line or at the end of a line of code.
- Explain WHY, not WHAT - the code already shows what it does
- Keep comments up to date when you change the code
- Use comments sparingly - clean code should mostly speak for itself
> A misplaced comment symbol is preventing this variable from getting its value. Find and remove the extra tile.
SyntaxError: the comment symbol makes Python ignore the value
- Explain why, not what
- Comment tricky logic
- Keep comments up to date
- Restate obvious code
- Leave outdated comments
- Over-comment simple lines
> You are a junior analyst at Accenture building a Python cost estimator that takes project parameters and prints a formatted breakdown for client proposals. The script must name every cost component, identify its type, compute totals, display results, and document assumptions inline.
int headcount from float hourly_rate and str labels so operations like multiplication stay type-safe.str, int, float, bool# and document your codeYour first lines of Python start here
- Category
- Python
- Difficulty
- beginner
- Duration
- 18 minutes
- Challenges
- 0 hands-on challenges
Topics covered: Variables and Assignment, Data Types, Print Statements, Basic Operators, Comments
Lesson Sections
- Variables and Assignment (concepts: pyVariables)
Variables are the foundation of any Python program. They let you store, reference, and manipulate data throughout your code. Creating Variables In Python, you create a variable by assigning a value to a name using the equals sign. Python automatically determines the data type based on the value you provide. Each variable stores a different type of data. Python figures out the type automatically, so you never need to declare it explicitly. Python itself has an origin story that surprises most peo
- Data Types (concepts: pyDataTypes)
Every value in Python has a type that determines what operations you can perform on it. Understanding data types helps you work with different kinds of information correctly. Core Built-in Types Python has four fundamental types you will use constantly: strings for text, integers for whole numbers, floats for decimals, and booleans for true/false values. Choosing the right data type matters. Performing math on strings or logic on integers leads to unexpected results or errors.
- Print Statements
Displaying output is essential for debugging, showing results, and communicating with users. Python makes this straightforward with the print function. Basic Output F-Strings for Formatting F-strings (formatted string literals) let you embed variables directly inside strings by prefixing the string with "f" and placing variables in curly braces. The print function accepts multiple arguments separated by commas. By default it inserts a space between each value and ends with a newline character. F
- Basic Operators (concepts: pyArithmetic)
Operators are symbols that perform operations on values. Python supports several categories of operators, each serving a specific purpose in your code. Arithmetic Operators Arithmetic operators perform mathematical calculations. Addition, subtraction, multiplication, and division work as you would expect. Comparison Operators Operator precedence in Python follows the standard mathematical order. Multiplication and division are evaluated before addition and subtraction unless parentheses override
- Comments
Good code communicates its intent. Comments let you explain why your code works the way it does, making it easier for others (and your future self) to understand. Single-Line Comments Notice how Python completely ignores the comment lines. They exist only for humans reading the code. Writing clear comments is a skill that separates professional code from amateur code. Knowing when and how to comment is just as important as knowing the syntax. Here are some patterns to follow and avoid. Multiline