Python Fundamentals

Common REPL Mistakes

Python Fundamentals

Check out a free preview of the full Python Fundamentals course

The "Common REPL Mistakes" Lesson is part of the full, Python Fundamentals course featured in this preview video. Here's what you'd learn in this lesson:

Nina demonstrates an error that may occur when reassigning reserved variables, how to write comments, and the basics of how to debug in the REPL


Transcript from the "Common REPL Mistakes" Lesson

>> Nina Zakharenko: This REPL is where we're going to live for class. It's where you're going to experiment, answer your own questions, etc. There's only just a few don'ts about variables in Python. The first is that they cannot start with a number. So if I type 3x equals 4, I'm going to get an error.

>> Nina Zakharenko: Let's quickly talk about this. Syntax error, invalid syntax. So it sounds kind of really scary, what's going on? the thing that you have to know about tracebacks, when you're get an error, when an exception is thrown, you're gonna get a traceback. You wanna read them from the bottom to the top, line by line.

And then they'll make a lot more sense. So here we'll see, we got a syntax error, invalid syntax. I just said variables in Python can't start with a number, tried to do it anyway. In the REPL, we'll see this kinda handy arrow pointing exactly where the problem was.

Then it'll show you the expression. And once we start running Python code from files, we'll see the file here.
>> Nina Zakharenko: Besides for this, and a few other things, Python really doesn't stop you from doing a lot, which can be problematic at times. So don't type in what I'm typing in.

>> Nina Zakharenko: So in Python we have a built-in type called list. I can easily name my variable list, oops.
>> Nina Zakharenko: And override the built in type. So don't do that, cuz now if I try to make a new list, it's gonna say int object is not callable, type error, why is that?

Because I just set list to 1. Okay so we're gonna talk about lists, dictionaries, sets, integers. A few other data types. If you want to make a list you can call it myList, right? Don't call your variable name list. There's a trick to clear out of this bad state.

But I'm not going to show it to just yet. In the meantime, you can press, hopefully none of you type this in. But I'm just going to exit out of my REPL, and then start it back up again. This time I just pressed the up arrow and found this command that VS code auto inserted, and got right back here.

Okay, so-
>> Speaker 2: I've got a question. With the hashtag that you did don't type this in. Is that like a comment that you can put into the REPL?
>> Nina Zakharenko: It's a comment.
>> Speaker 2: Okay, thank you.
>> Nina Zakharenko: Yeah, you probably won't be putting comments into your REPL. But you can if you want to.

You just have to remember to enter an extra space when you're done. I'm sorry, press enter an extra time once you're done with a comment.
>> Nina Zakharenko: Okay, so all of you should have the REPL open by now. Just a heads up, the easiest way to save the contents of your REPL after class if you'd like to, you can just right click here, select all, copy and paste.

You can do that at the end of the class. Unless you quit VS Code, or hit this delete icon like I did, your REPL should be there with all of its information.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now