The Basics - Tasks
We are going to start from scratch and build up some basic skills in Python. Follow the steps below to get started.
Get Python and your IDE (VS Code, Positron, or RStudio) running (see Prerequisites if needed) before starting.
Setting up your first(?) project:
In your IDE (VS Code example shown), go to
File>New Folder...and name itDS-intro-2025.- Alternatively, open a terminal and run:
mkdir DS-intro-2025 - Open the folder in your IDE.
Note: The exact steps may vary slightly in Positron or RStudio, but the concept of project organization remains the same.
- Alternatively, open a terminal and run:
Create two folders in the project directory:
dataandscripts.
Now using the console only:
Type:
print("Hello, world!")and hit Enter to see the output.Now try:
2 + 2and hit Enter.Find what the current working directory is by typing:
import os os.getcwd()Assign the value
10to a variable namedmy_numberusing the assignment operator=.Print the value of
my_numberto the console. Did it work?
Now, let’s create your first Python script:
- In VS Code, go to
File>New Fileand save it with a.pyextension.
Python scripts allow you to write and save your code. You can run the code directly from the script, and it helps you keep your work organized.
Think of the script as a recipe that you can follow again and again! If you want to repeat your analysis or share it with others, having it in a script makes it easy.
All lines in the script that start with # are comments. They are not executed as code but are there to help explain what the code does.
Save the script in the
scriptsfolder as1-basics-intro.py.Type the following code in the new script:
# This is my first Python script
print("Hello, world!")
my_number = 10
print(my_number)Run the code in the script by clicking the play button or using the terminal:
python scripts/1-basics-intro.py. Observe the output.Create a list with 1000 random numbers between 0 and 100. For this, you can use the
randommodule. Assign this list to a variable namedrandom_numbers. Check how to specify the range in therandom.uniform()function by typinghelp(random.uniform)in the console.
import random
random_numbers = [random.uniform(0, 100) for _ in range(1000)]- Install the
pandaspackage by typingpip install pandasin the terminal. We won’t use it now, we will import it in the next part.
Optional:
- Calculate the mean and standard deviation of the
random_numberslist using thestatisticsmodule ornumpy. Print the results to the console. - Save your script by clicking
File>Saveor pressingCtrl + S(orCmd + Son Mac).
R version: If you prefer R, the same exercises are available in R. Create a new R script (1-basics-intro.R) and follow the equivalent steps using R syntax (e.g., print("Hello, world!"), my_number <- 10, runif(1000, 0, 100)).