Introduction to Python
pandas
R.
| Paradigm | Language | Focus | Example |
|---|---|---|---|
| FP | R |
What to do with objects | |
| OOP | Python | What the object does | |
In Python, objects have built-in behavior; in R, behavior is typically external to the object.
| Data type | R | Python |
|---|---|---|
| Integers | numeric |
int |
| Floating point numbers | numeric |
float |
| Boolean values | logical |
bool |
| Strings | character |
str |
In Python, objects contain functions, methods, and attributes:
len(my_list)).my_list.append(42)).my_list.size)We use . to call functions/methods/attributes from objects.
R relies heavily on vectorized operations and functional tools for many tasks.
Python, by contrast, emphasizes explicit control over how code is executed.
In Python, control flow is how we:
The core building blocks of control flow in Python are:
if statements, which run code only if a condition is Truewhile loops, which repeat code while a condition remains Truefor loops, which run code for each item in a container (like a list or dictionary)break and continue statements, which allow you to modify the behavior of loopsEach of these relies on Boolean values: data types that can only be True or False.
a.w.koh@bham.ac.uk
https://allisonkoh.github.io/
🦋 @allisonwkoh