Numbers, Strings, and Booleans

Site Admin · 11 Sep 2026 · 8 views

Numbers, Strings, and Booleans

The Building Blocks

Every Python program is built from a small set of data types. In this post you will learn the three fundamentals: numbers, strings, and booleans. Once you can combine these, you can write programs that compute results, format messages, and make decisions.

Numbers

Python supports integers (whole numbers without a decimal part) and floats (numbers with a decimal part). Arithmetic works with the usual operators: + for addition, - for subtraction, * for multiplication, and / for division. Python also offers // for floor division, % for the remainder, and ** for powers.

price = 9
quantity = 3
total = price * quantity
print(total)        # 27
print(10 / 4)       # 2.5
print(10 // 4)      # 2
print(10 % 3)       # 1
print(2 ** 8)       # 256

The round function and the int and float conversions help you format results. int("42") turns the string "42" into the number 42, which is handy when reading input.

Strings

A string is a sequence of characters wrapped in single or double quotes. Strings support a powerful set of methods: .upper() and .lower() change case, .strip() removes surrounding whitespace, and .replace() swaps text.

message = "  hello world  "
print(message.strip().upper())    # HELLO WORLD
print(len(message))               # 15
print(f"Total: {total} items")   # f-string formatting

F-strings, written with an f before the opening quote, let you insert values directly into text using curly braces. They are the modern, readable way to build messages in Python.

Booleans

Booleans have exactly two values: True and False. They come from comparisons such as == (equal), != (not equal), < (less than), and > (greater than). Booleans power if statements, which you will see next.

print(total > 20)     # True
print(total == 26)    # False

Key Points

  • Use ints for whole numbers and floats for decimals; watch out for rounding in floats.
  • Operators include +, -, *, /, //, %, and **.
  • Strings support methods like .upper(), .strip(), and .replace().
  • F-strings embed values into text with f"...{var}...".
  • Booleans (True and False) come from comparisons with ==, !=, <, and >.
Share this post:

Comments (0)

Please login or register to comment.