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

Daily Life
Interviews

Store and reuse values in your code

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.
1name = "Alex"
2age = 25
3salary = 75000.50
4is_active = True
5
6print(name, age, salary, is_active)
>>>Output
Alex 25 75000.5 True
Each variable stores a different type of data. Python figures out the type automatically, so you never need to declare it explicitly.
Dynamic typing
Dynamic typing
Python infers the type from the assigned value automatically
Reassignment
Reassignment
Variables can be updated to hold a new value at any time
Type awareness
Type awareness
Use type() to check what type a variable currently holds
Python itself has an origin story that surprises most people.
Fill in the Blank

> You want to store the number 10 in a variable called x. Pick the correct operator to assign the value.

x  10
print(x)
Variable names in Python are case-sensitive. The names count, Count, and COUNT all refer to three completely different variables.
Python naming conventions recommend lowercase with underscores for variable names, a style known as snake_case that distinguishes Python from languages that use camelCase.

Data Types

Daily Life
Interviews

Work with numbers, text, and booleans

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.
strintfloatbool
str
Text strings
Words, sentences, or text
int
Whole numbers
Counting and indexing ops
float
Decimal values
Measurements and ratios
bool
True or False
Logic and conditionals
Choosing the right data type matters. Performing math on strings or logic on integers leads to unexpected results or errors.
Fill in the Blank

> Every value in Python has a type. Pick different values to discover what type Python assigns to each one.

x = 
print(type(x))
TIP
Use type() to check a variable's type when debugging. This is especially helpful when data arrives from external sources like files or APIs.

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

Daily Life
Interviews

Display output from your programs

Displaying output is essential for debugging, showing results, and communicating with users. Python makes this straightforward with the print function.

Basic Output

The print() function displays output to the console. You can print simple text, variables, or formatted strings.

//

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.
1name = "Alex"
2age = 25
3print("Hello, World!")
4print(f"Name: {name}, Age: {age}")
>>>Output
Hello, World!
Name: Alex, Age: 25
Python Quiz

> 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}")
r
name
b
f
age
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-strings evaluate expressions inside the curly braces at runtime, so you can embed calculations like {price * 1.08} directly inside the string.

You can change the separator between printed values using the sep argument, and suppress the trailing newline with end="".

Debug Challenge

> This print statement runs but has unnecessary double parentheses. Remove the extra tile to clean it up.

Code runs but has unnecessary double parentheses

Printing is not the same as returning. A function that prints a value does not make that value available for further computation by the caller.
In production code, structured logging is preferred over print statements since it supports log levels, timestamps, and filtering without changing the code.
During development, print statements are a quick debugging tool, but removing them before committing is a good habit to keep production output clean.

Basic Operators

Daily Life
Interviews

Do math and combine values in code

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.
1total = 10 + 5
2difference = 10 - 3
3product = 4 * 3
4quotient = 15 / 4
5
6print(total, difference, product, quotient)
>>>Output
15 7 12 3.75
Fill in the Blank

> 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.

1is_equal = (10 == 10)
2is_greater = (10 > 5)
3
4print(is_equal)
5print(is_greater)
>>>Output
True
True
Python Quiz

> 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.

Operator precedence in Python follows the standard mathematical order. Multiplication and division are evaluated before addition and subtraction unless parentheses override the order.

Augmented assignment operators like += and *= update a variable in place. Writing count += 1 is equivalent to count = count + 1 but more concise.

Comments

Daily Life
Interviews

Document your code for future readers

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

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.

1# This is a single-line comment
2name = "Alex" # Inline comment
3
4# Calculate tax at 8.5% rate
5price = 100
6tax = price * 0.085
7print(f"Tax on {price}: {tax}")
>>>Output
Tax on 100: 8.5
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.
THREE RULES FOR GOOD COMMENTS
  • 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
Knowing when and how to comment is just as important as knowing the syntax. Here are some patterns to follow and avoid.
Debug Challenge

> 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

Do
  • Explain why, not what
  • Comment tricky logic
  • Keep comments up to date
Don't
  • Restate obvious code
  • Leave outdated comments
  • Over-comment simple lines
Multiline comments in Python are typically written as multiple consecutive single-line comments. Triple-quoted strings are sometimes used but are technically string literals, not true comments.
Good comments document intent, edge cases, and the reasoning behind non-obvious decisions. They are written for the next developer who reads the code, including your future self.
PUTTING IT ALL TOGETHER

> 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.

Variables and assignment store each cost component such as hours and rate so the value can be referenced by a descriptive name throughout the estimator.
Data types distinguish int headcount from float hourly_rate and str labels so operations like multiplication stay type-safe.
Basic operators compute derived totals with expressions like subtotal = hours * rate and percentage = tax / subtotal * 100.
print() outputs each formatted cost line to the console and comments document why specific rates or assumptions were chosen.
KEY TAKEAWAYS
Variables store data values and are created through assignment
Python has multiple data types: str, int, float, bool
print() displays output to the console
Comments start with # and document your code

Your 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

  1. 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

  2. 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.

  3. 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

  4. 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

  5. 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