Skip to content

Python Basics

Strings and print()

Python
project_name = "Payments API"
slug = "payments-api"

Strings support useful methods.

Use print() to see the result:

Python
name = "  Payments API  "

print(name.strip())
print(name.lower())
print(name.upper())
print(name.replace(" ", "-"))

Integers and Floating-Point Numbers

An integer is a whole number:

Python
task_count = 3
retry_limit = 5

A floating-point number is a number with a decimal point:

Python
completion_ratio = 0.75
average_seconds = 2.5

Note

Python does not have a separate double type the way some languages do. In Python, a decimal number like 2.5 is usually a float.

Arithmetic

Python
completed_tasks = 8
planned_tasks = 3

total_tasks = completed_tasks + planned_tasks
remaining_tasks = total_tasks - completed_tasks
twice_remaining = remaining_tasks * 2
average = total_tasks / 2

print(total_tasks)
print(remaining_tasks)
print(twice_remaining)
print(average)

Common arithmetic operators:

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • // integer division
  • % remainder

Booleans

A boolean is either True or False.

Python
archived = False
is_admin = True

None

None means "no value".

Python
due_date = None
description = None

I use None when a value is missing on purpose, not when it is an empty string or zero.