JEPA4Japan · tutorials

Values, Variables, and Types

1,026 words 5 min read #Python

Work with names, core value types, conversions, arithmetic, and formatted output.

Course progress Course outline 24 of 24 lessons available

Open the labeled boxes

In Chapter 1, name and dream remembered answers for your Dream Card. Imagine each name as a label stuck to a box. The thing the label points to is a value, and every value has a type.

  1. Value the thing Python uses
  2. Variable a name pointing to it
  3. Type what kind of thing it is
A variable is a label; a value is the thing; a type tells Python what fits.

Ask Python to inspect five useful values:

print(type("Python"))
print(type(30))
print(type(3.5))
print(type(True))
print(type(None))

Output:

<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>
<class 'NoneType'>

Read class here as “type.” str is text, int is a whole number, float is a decimal-shaped number, and bool is either True or False. None means “there is no useful value here yet.”

Quotes change the type: "12" is text, but 12 is an integer. Likewise, "False" is ordinary text, not the Boolean value False.

Labels can move

An equals sign assigns a value to a name:

minutes = 30
print(minutes)

minutes = 45
print(minutes)

Output:

30
45

The second assignment moves the label minutes to a new value. It does not claim that 30 and 45 are equal.

Use names that explain their jobs, such as minutes_per_day and number_of_days. Python names usually use lowercase words joined by underscores. A name cannot start with a number or contain a space or hyphen. Do not use built-in names such as str, int, input, or print for your variables.

Names can point to calculated values too:

minutes_per_day = 30
days = 7
total_minutes = minutes_per_day * days

print(total_minutes)
print(total_minutes / 60)

Output:

210
3.5

Python knows +, -, *, /, // for floor division, % for a remainder, and ** for a power. Multiplication and division happen before addition and subtraction. Parentheses make your intended order obvious: (10 + 5) * 2 is 30, while 10 + 5 * 2 is 20.

The keyboard sends text

input() always returns a string, even when someone types digits. Python cannot guess whether 30 means minutes, a house number, or part of a name.

  1. Type 30 the keyboard sends text
  2. "30" input() returns str
  3. Convert int("30") becomes 30
  4. Calculate now number rules apply
Input arrives as text; convert it when your program needs a number.

See the difference:

first = input("First number: ")
second = input("Second number: ")
print(first + second)

Typing 20 and 5 prints 205, because + joins strings. Convert at the doorway:

first = int(input("First whole number: "))
second = int(input("Second whole number: "))
print(first + second)

Now the same answers print 25. Use int() for whole-number text, float() for decimal text, and str() when you deliberately need text.

An f-string mixes labels and values neatly:

topic = "Python"
hours = 210 / 60
print(f"Study {topic} for {hours:.1f} hours.")

Output:

Study Python for 3.5 hours.

The f turns expressions inside braces into text. .1f changes only the display to one decimal place; it does not change the stored value.

Build a Study Time Calculator

This complete mini-project uses only Python’s built-in standard-library tools. Save it as study_time.py.

  1. Ask topic, minutes, days
  2. Calculate daily time × days
  3. Show a friendly plan
Text comes in, numbers are converted, and named results come out.
topic = input("Topic: ")
minutes_per_day = int(input("Minutes per day: "))
days = int(input("Number of days: "))

total_minutes = minutes_per_day * days
total_hours = total_minutes / 60

print()
print(f"Topic: {topic}")
print(f"Daily practice: {minutes_per_day} minutes")
print(f"Plan: {total_minutes} minutes")
print(f"Total time: {total_hours:.1f} hours")

Run python3 study_time.py and enter Python, 30, and 7. Verify the final lines:

Topic: Python
Daily practice: 30 minutes
Plan: 210 minutes
Total time: 3.5 hours

Before a second run, predict the answer yourself. Try 45 minutes for 4 days: the program should show 180 minutes and 3.0 hours.

Three tiny missions and one sharp corner

  1. Type detective. Predict, then print, the types of "7", 7, 7.0, False, and None.
  2. Temperature card. Read Celsius with float(), calculate celsius * 9 / 5 + 32, and show one decimal place. For 20, verify 68.0.
  3. Longer plan. Add weeks, calculate total_days, then recalculate total minutes and hours with clear variable names.

Sharp corner: int("thirty") and int("30.5") raise ValueError. For now, type the requested kind of number. Zero is valid arithmetic, but a negative study time makes little real-world sense. Chapter 10 will teach the program to reject bad input kindly.

Ready for decisions?

  • I can tell a value, a variable, and a type apart.
  • I can recognize str, int, float, bool, and None.
  • I can assign and reassign a clear variable name.
  • I can use arithmetic and parentheses.
  • I know that input() always returns text.
  • I can convert input and format a result with an f-string.
  • My calculator produces 210 minutes and 3.5 hours for 30 × 7.
  • I completed the three tiny missions.

Next, you will make Boolean questions and use their answers to choose a path or repeat a job.