Academy
Learn Python by running it
Short lessons, each with a live editor underneath. Read the idea, run the code, change it, see what happens. Nothing to install.
Academy
Short lessons, each with a live editor underneath. Read the idea, run the code, change it, see what happens. Nothing to install.
A variable is a name that points to a value. You create one with =. The print() function shows values in the output. You can pass several values to print separated by commas, and Python puts a space between them.
Run the example, then try changing the name or adding a line of your own.
Python does arithmetic with the usual symbols. Use ** for powers and % for the remainder. The math module adds functions and constants like math.pi. Bring it in with import math before you use it.
round(value, 2) rounds a number to two decimal places, which is handy when printing results.A list holds many values in order, written inside square brackets. Built in functions like len, max, min and sum work on lists directly. A for loop visits each item in turn, and enumerate hands you the position alongside the value.
The line that starts with f"..." is an f-string. Anything inside the curly braces is replaced by its value.
A function packages a piece of logic so you can reuse it. Define one with def, give it inputs in the parentheses, and hand back a result with return. Once defined, you call it as many times as you like.
NumPy is the foundation of scientific Python. An array is like a list, but math applies to every element at once, which is both faster and easier to read. np.linspace(a, b, n) makes n evenly spaced numbers from a to b.
Notice how x ** 2 squares the whole array in one step, with no loop.
Matplotlib turns numbers into figures. Build the data, call plt.plot for each series, then plt.show(). The chart appears right below the editor. Try changing the function or adding a third line.
Pandas gives you the DataFrame, a table with named columns. You can build one from a dictionary, print it, and pull out answers with simple expressions. This is the workhorse for any data task.
Ready for your own work? Open the full workspace with files, plots and saved sessions.
Launch the workspace →