Skip to content

Variables and Data Types

Variables

A variable gives a name to a value:

Python
name = "Developer Portal"
priority = "high"
task_total = 12

Warning

Because Python is dynamically typed, the type of the variable can be reassigned later on.

Python
task_total = task_total + 1

task_total = "Five"

Type Conversion

Python lets you convert one type into another by passing it into a constructor of that type.


Python
task_count = int("12")
completion_ratio = float("0.75")
archived = bool(0)

print(task_count)
print(completion_ratio)
print(archived)

Comparisons

I can compare values with operators such as:

  • == equal to
  • != not equal to
  • < less than
  • > greater than
  • <= less than or equal to
  • >= greater than or equal to
Python
task_count = 3

print(task_count == 3)
print(task_count > 1)
print(task_count < 10)

Comparisons return booleans.