Skip to main content
#python#variables#data-types#operators

Variables in Python

Notes on Python variables and how values acquire types at runtime.

#📚 Variables

TypeDescriptionExample
NumberHolds numeric values such as integers or floating-point numbers0, 1.25, or -231
StringHolds text’string’
ListA collection that can hold different types of values[1, ‘hi’, -123]
TupleAn immutable sequence(1, ‘hi’, -123)
DictionaryMaps keys to values{‘name’: ‘python3’}
………

Python does not require a type declaration when you first use a variable.

  • The object you assign to a name has a type.
  • That type determines which operations and methods are available.

#🔢 Numeric variables

OperationSymbolExampleValue
Addition+4 + 59
Subtraction-5 - 41
Multiplication*5 * 420
Division/5/41.25
Exponentiation**5 ** 3125
Remainder%11 % 65
Floor division//11//61
…………

#Numeric notation

NotationMarkerExampleResult
Octalo0o10064
Hexadecimalx0x100256
ExponentialE12E21200
Complexj1+2j1+2j

Connect