Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Basic Functionality of Jupyter Notebooks

This lesson explores the basic functionality of Jupyter Notebooks. The lesson will show you how to write code in single code blocks as well as how to separate the code into multiple logical chunks. You’ll see how easy and intuitive Jupyter is to use, especially for new developers.

00:00 With our Jupyter Notebooks set up and running, let’s now take a look at the basic functionality. So now I’m here inside of this new Notebook that I just created before, and we see that there’s a code cell that’s already marked for us, and I can just click in there with my mouse and then start typing some Python code.

00:22 Better not have it capitalized.

00:31 And now, as I said before, we get this read-evaluate-print loop thing right in here, which means that we can see our output right inside of this document.

00:41 So what I can do now here is I can say, “Run this,” and I can see my Python output in the same document where I just wrote my code. What else can I do?

00:53 So, what I mentioned also before is that everything lives inside of memory, which means that if I define a variable here—let’s call it greeting

01:04 and then run this code block, then I’m going to be able to access the variable that I just defined in a different code block. So, I can say greeting and try autocomplete with Tab.

01:16 Jupyter already knows that this exists, so it autocompletes this for me. I can run this and get the same output that I would get when entering a variable name and pressing Enter inside of a Python interpreter.

01:26 So, this is great! What else can we see here on the site? It tells us In and the number, and this just talks about the code blocks and in which order they were run, so this was the first code block that was run. Afterwards, we ran that one, and then this one. And in case there’s some output, we also get here an Out and from which code block did it come from. Now, if I run this one again, it’s going to overwrite the number in here.

01:53 See, because it was the fourth code block that was run, now. This also means that I’m able to access the variable that I just created down here in a code block further above. So I can go back here, move that, and pass in greeting, instead.

02:11 I get the same output because I’m using this variable that you defined further down. So you can see that everything lives inside of memory and I have the advantage of executing single code blocks to see what is the output, but at the same time, reusing everything that I create within a document in any code cell available. This is great for data exploration, where you just want to try out something, look into a table, change something, even just find out what you’re supposed to do in the process. And for this, having this incremental way of running code is great. So, you can see in here, this environment is already a great place for learning about Python programming, getting started. I’m going to remove some cells.

02:58 For example, I can just play around and try out things. I can say…

03:17 Run the cell, get an output.

03:25 So, while I mentioned before that Jupyter’s great for data exploration and data analysis, I think it is also actually a great playground for getting started with programming because it is very intuitive; you have menu items that we’re going to go over in a moment; and you can try small pieces of code and see the output right away, without needing to write a long script or finding a way around in the Python interpreter or inside of a complicated IDE.

03:54 Fine. Let’s take a look at the menu items next.

Avatar image for Pygator

Pygator on Aug. 18, 2019

Joel Grus has made a good video about all of the cons of jupyter notebooks like one being able to run cells out of order. There can be many hard to catch bugs that surface.

Avatar image for Martin Breuss

Martin Breuss RP Team on Aug. 25, 2019

Good point, check it out here: www.youtube.com/watch?v=7jiPeIFXb6U - always good to know the pros and cons.

Avatar image for thomasknebel

thomasknebel on March 21, 2020

Around 2:50 you remove some cells, but I didn’t understand how you removed the cells?

Avatar image for Martin Breuss

Martin Breuss RP Team on March 21, 2020

Hi @thomasknebel, it’s a keyboard shortcut that you can invoke by pressing the x character. You can see it popping up in the bottom left corner on a gray background. I’m talking more about the different keyboard shortcuts in the next video around 4:30.

Avatar image for DoubleA

DoubleA on Feb. 8, 2021


Hi there. Thanks for the tutorial. I also love JN, but the problem I always run into is that the speed of code execution decreases nearly linearly with the length of my notebooks. I am working a lot with the NLTK guide by doing tons of exercises using JN. My notebooks start crashing once they reach a certain length. I start nticing it when I start running something like conditional frequency distribution or try to build a plot even over a medium-size dataset. This is really annoying, because I find myself spending tons of time trying to figure out what makes my JN freeze or even crash while there’s in fact no issue with my code. All in all, JN is an extremely useful tool, but I’d recommend keeping those notebooks pretty short (under 100 lines of code or something).

Become a Member to join the conversation.