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:
| Name | Short | Example | Notes |
|---|---|---|---|
| Integer | int | -50, 0, 2500 | Whole numbers, no decimal |
| Float | float | 1.23, -10.8 | Real-valued, decimal numbers |
| Boolean | bool | True, False | Only two possible values |
| String | str | 'hello', "world" | Sequence of characters in quotes |
Complex datatypes:
| Name | Short | Description |
|---|---|---|
| List | list | Ordered collection; any mix of types allowed |
| Dictionary | dict | Unordered set of key–value pairs |
| Null value | None | Represents 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.