← Lectures·L3

Python Basics II

Prof. Dr. Nicolas Rohleder, Prof. Dr. Björn Eskofier, Veronika Ringgold, Luca Abel, Robert Richer · 8 concepts · 10 questions

Concept 1 / 8

Python Datatypes: Basic and Complex

Every value in Python belongs to a datatype — a category that tells the interpreter how to store and operate on that value. Understanding datatypes prevents cryptic errors and makes it easier to reason about your code.


Basic datatypes:


NameShortExampleNotes
Integerint-50, 0, 2500Whole numbers, no decimal
Floatfloat1.23, -10.8Real-valued, decimal numbers
BooleanboolTrue, FalseOnly two possible values
Stringstr'hello', "world"Sequence of characters in quotes

Complex datatypes:


NameShortDescription
ListlistOrdered collection; any mix of types allowed
DictionarydictUnordered set of key–value pairs
Null valueNoneRepresents the absence of a value

When Python cannot figure out how to apply an operator to two incompatible types, the program crashes with a TypeError. Thinking ahead about what type a variable should hold helps avoid these crashes.