REPL, Notebooks and DevTools
Level 3 · Trying code out
Three places to try code and see the answer at once. A REPL runs in the terminal. A notebook saves it. DevTools sit in the browser.
Course contentsLesson 6 of 13
Level 1 · The editor
Level 2 · Checking and fixing code
Level 3 · Trying code out
Level 4 · Other people's code
Level 5 · Building the project
After this lesson you can
- Try a line of code in a REPL
- Say what a notebook cell is
- Open DevTools and read an error
11 mincovers 3 glossary entries
Worth reading first: Debuggers and Breakpoints
Where to try one line of code and see the answer
A REPL lets you type one line of code and see the answer at once. The name stands for read, eval, print, loop. Type python3 in a terminal, then 2 + 3, and it prints 5 and waits for the next line. It is the fastest way to test a small idea.
Python's REPL shows three greater-than signs while it waits. Type node instead, and you get one for JavaScript. Type a word in quotes with .upper() after it, and it prints the word in capitals. You find out what a line does in two seconds, without making a file.
When you close a REPL, the code is gone. That is fine for a quick test and bad for real work. Anything you want to keep belongs in a file, such as a .py file you can run again.
A Jupyter Notebook keeps the quick answers and saves them. It is a page split into cells. A code cell runs when you press Shift and Enter, and its output shows just below it, even a chart. A text cell holds notes. The file ends in .ipynb, and people in data and science use it a lot.
Cells can run in any order, and that is the notebook's trap. Run cell 5 before cell 3, and the page shows results that running it from the top would not give. Before you share a notebook, restart it and run every cell from the top.
Browser DevTools are the same idea for web pages. They are built into every major browser. The Elements tab shows the page's HTML and CSS, and you can change them live. The Console shows errors and runs JavaScript. The Network tab lists every file the page asked for.
In Chrome you open DevTools with F12, or by right-clicking and choosing Inspect. A change you make there is gone when you reload the page. It is a place to try a fix, then copy it into your own files.
$ python3
>>> 2 + 3
5
>>> "hi".upper()
'HI'Worked example
Lucy fixes a button in the browser
Lucy's button sits 20 pixels too low. She opens DevTools with F12, picks the button and tries three margin values in the Elements tab.
The third one looks right. She copies that one line into her CSS file, saves, reloads, and the fix stays.
The words for this lesson3
Check yourself
Why did my change in DevTools disappear?
Finished this lesson?
Marking it complete also marks its 3 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.