1. data types
Python's Core Data Types
Every value in a program has a type— it tells Python how much memory to set aside and what operations are allowed on that value. You don't have to declare types yourself; Python figures them out automatically when you write a value.
The main types you'll use in Python are:
- int — whole numbers:
42,-7,0 - float — decimal numbers:
3.14,-0.5,2.0 - str — text (string):
"hello",'world' - bool — truth values:
TrueorFalse
Every type in one snippet:
age = 25 # int price = 9.99 # float name = "Ada" # str is_student = True # bool
Question 1 of 5
What data type is the value `3.14` in Python?
2. use cases
When to Use Each Type
Choosing the right type makes your code clearer and easier to reason about. Here are the best-fit uses for each regular type, plus a simple example you could see in a real program:
- int — counting whole items (no decimals).
- float — measurements or values with decimals.
- str — names, labels, and text.
- bool — yes/no or true/false conditions.
Use cases in code:
num_students = 28 # int temperature_c = 21.5 # float welcome_text = "Hello!" # str is_logged_in = False # bool
3. variables
Storing Values in Variables
A variable is a named container for a value. You create one with an assignment statement:
name = value
Unlike some languages, Python requires no keyword like let or var. Assigning to an existing name simply replaces the stored value — variables can even change type between assignments.
The built-in type() function tells you the type of any value or variable:
Creating, re-assigning, and inspecting variables:
# Create a variable score = 100 # Re-assign it score = 42 print(score) # 42 # Check its type print(type(score)) # <class 'int'> # A variable can change type score = "pending" print(type(score)) # <class 'str'>
Question 1 of 5
What type does `x = 42` create?
4. naming
Naming Conventions
Python doesn't enforce names — technically x = 42 and user_age = 42both work. But good names make code readable at a glance. Python's community follows PEP 8, which recommends:
- Use snake_case for variable names: all lowercase, words separated by underscores (
first_name,total_price). - Be descriptive —
user_agebeatsaorx1. - Names must start with a letter or underscore — not a digit.
- Names are case-sensitive:
Score,score, andSCOREare three different variables. - Avoid Python's reserved keywords (
if,for,True, etc.) as variable names.
Good names vs. bad names:
# ✗ Hard to read a = 25 x1 = "Ada Lovelace" TotalPrice = 9.99 # ✓ Clear and conventional user_age = 25 full_name = "Ada Lovelace" total_price = 9.99
Question 1 of 4
Which variable name follows Python's snake_case convention?
5. project
First Program
Put everything together by writing and running your first Python script. You'll install Python, create a file, declare a string variable, and print it to the console.
First Program
- 1.Install Python from python.org (choose the latest stable release and check 'Add Python to PATH' during setup).
- 2.Create a new file called
hello.pyin any folder on your computer. - 3.Open
hello.pyin a text editor and type:greeting = "Hello, World!"then on the next line:print(greeting) - 4.Open a terminal (Command Prompt / Terminal), navigate to the folder containing
hello.py, and run:python hello.py— you should see Hello, World! printed.