Welcome to your first lesson! Our ultimate goal is to build powerful web APIs with FastAPI, but to do that effectively, we first need to build a solid foundation in the Python language itself. This course starts with the essentials of Python, and this first lesson will focus on the most fundamental building blocks of any program: variables and data types.
By the end of this lesson, you will be able to define variables to store information and understand Python's basic data types: strings for text, integers and floats for numbers, and booleans for true/false values. These concepts are the bedrock upon which all your future Python and FastAPI code will be built.
What Are Variables?
In programming, we constantly need to work with data. A variable is a name we give to a location in the computer's memory where we can store a piece of data. Think of it as a labeled box: you give the box a name (the variable name) and put something inside it (the value). You can then use that name to refer to the value anywhere in your program.
To get a clear picture of this, let's start with a video from Programming with Mosh, which explains this concept and introduces the different kinds of data we can store. The video also covers important conventions for naming variables, which is a crucial practice for writing clean, readable code.
Python Variables - Python Tutorial for Beginners with Examples | Mosh
Please watch the video from the beginning until the end.
Pay close attention to the following points: The analogy of a variable as a label for a memory location. The introduction to the four "primitive" types: integers, floats, booleans, and strings. The best practices for naming variables, often referred to as PEP 8 guidelines.
To summarize the key takeaways on variable naming from the video:
- Be descriptive:
order_countis much better thanoc. - Use lowercase letters: Variable names are typically written in all lowercase.
- Separate words with underscores: This style is called
snake_case(e.g.,first_name,is_active). - Proper spacing: Use a single space around the equals (
=) sign for readability (e.g.,age = 30, notage=30).
In Python, assigning a value to a variable is straightforward. You use the assignment operator (=):
# variable_name = value
student_count = 1000
course_name = "Python for FastAPI"
is_published = True
Basic Data Types in Python
The type of data a variable holds determines what you can do with it. You can perform arithmetic with numbers, but you can't with text. Python has several built-in data types. For this lesson, we will focus on the four most common ones you just saw in the video.

An important feature of Python is that it is dynamically typed. This means you don't have to explicitly declare the data type of a variable. Python automatically infers the type based on the value you assign to it.
Let's explore each of the four basic types.
Integers (int)
Integers are whole numbers, without any decimal part. They can be positive, negative, or zero.
user_age = 25
items_in_stock = -10 # Maybe a backorder count
number_of_students = 0
The video from Bro Code offers a quick, practical demonstration of integer variables.
Python variables for beginners ❎
Watch this segment on integers.
This clip provides simple, real-world examples of integers like age, player counts, and item quantities.
Floats (float)
Floats, or floating-point numbers, are numbers that have a decimal component. Even if the decimal part is zero (like 10.0), Python considers it a float.
price = 19.99
gpa = 3.7
temperature = 98.6
Let's see a demonstration of floats from the same video.
Python variables for beginners ❎
Now, watch the part explaining floats.
The presenter uses clear examples like GPA and price to illustrate the concept.
Strings (str)
A string is a sequence of characters used to represent text. You can create strings by enclosing text in either single quotes ('...') or double quotes ("..."). The choice is a matter of style, but it's useful to be consistent. One benefit of having both is that it makes it easy to include a quote character within a string.
# Using double quotes
full_name = "Jane Doe"
# Using single quotes
favorite_language = 'Python'
# A string can contain quotes of the other type
message = "She said, 'Hello, Python!'"
This next clip shows how strings are defined and used.
Python variables for beginners ❎
This segment covers strings.
Notice how a string is just a series of text, and you can use single or double quotes.
Booleans (bool)
A boolean has only two possible values: True or False. They are essential for logic and control flow, such as in if statements to make decisions in your code. Note that in Python, the words True and False are case-sensitive and must be capitalized.
is_active_user = True
has_permission = False
Let's see the final clip on booleans.
Python variables for beginners ❎
Finally, watch this part about booleans.
This clip explains that booleans are binary values and highlights the common mistake of putting them in quotes, which would turn them into strings.
Checking a Variable's Type
Since Python figures out the data type for you, it can be useful to check what type it has assigned. You can do this with the built-in type() function.
For a quick reference on Python's data types and the type() function, you can review the following resource from W3Schools.
This page provides a concise overview of Python's built-in data types.
Focus on these parts: Review the table under the list of types. We've covered str, int, float, and bool today. Read the section "Getting the Data Type" to understand how the type() function works. Look at the table under "Setting the Data Type", which reinforces how Python infers the type from the value.
Here's how you'd use type() in practice. You can try this out in a Python interpreter.
name = "John"
year = 2053
temperature = 98.5
is_logged_in = True
print(type(name))
print(type(year))
print(type(temperature))
print(type(is_logged_in))
Running this code will produce the following output:
<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>
Diving Deeper
You now have a solid grasp of the basics. Given your background with a BCA, you might appreciate a more detailed exploration of these data types. The following article from Real Python is an excellent, in-depth resource. You don't need to memorize everything, but reading through it will strengthen your understanding.
Basic Data Types in Python: A Quick Exploration
This article provides a comprehensive look at Python's fundamental data types.
Read the following sections to build on what you've learned: Integer Numbers: Read from the start of this section to the end. It covers different ways to represent integers (like binary and hex) that you might encounter. Floating-Point Numbers: Read from the start of this section to the end of "The Built-in float() Function". Strings and Characters: Read from the start of the section up to the end of "The Built-in str() and repr() Functions". This section is quite detailed and covers f-strings, which are very useful. Booleans: Read the entire "Booleans" section. It clarifies how Python evaluates different objects in a boolean context (truthiness).
Conclusion
In this introductory lesson, we've covered the essential concepts of variables and Python's four basic data types.
Key Takeaways:
- A variable is a named container used to store data in memory.
- Python is dynamically typed, meaning it automatically detects a variable's type from the assigned value.
- The four fundamental data types are:
int: For whole numbers (e.g.,10,-5).float: For numbers with a decimal point (e.g.,3.14,-0.5).str: For textual data, enclosed in quotes (e.g.,"hello",'world').bool: For truth values,TrueorFalse.
- You can use the
type()function to inspect the data type of any variable. - Following good naming conventions (
snake_case, descriptive names) makes your code much easier to read and maintain.
These concepts are the absolute foundation of programming in Python. In our next lesson, we will build upon this by exploring how to store collections of data using Python's versatile data structures: lists, tuples, and dictionaries.