Python Fundamentals

Using the Python REPL

Python Fundamentals

Check out a free preview of the full Python Fundamentals course

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

Nina introduces the basics of how to use the Python REPL.


Transcript from the "Using the Python REPL" Lesson

>> Nina Zakharenko: We can just start typing stuff in here, and seeing how it works. Python knows about numbers, right?
>> Nina Zakharenko: So we can type some of that in here, and as we type commands and press Enter, we'll instantaneously see the result. You'll also notice here, these kinda three arrows, that indicates a Python REPL prompt.

The result has no symbol indications. If you see these arrows in the course website, you just click on the Copy button on the top right, and it'll copy without the arrows.
>> Nina Zakharenko: Can also declare some variables, just gonna say my name is Nina, I recommend you use your own name.

And then if we wanna see the value of that variable, we can just type it in and hit Enter, and we'll see what's stored in there. There are three very, very important methods that we're gonna be using throughout the class. So I recommend that you pay attention to these, the first one is type.

So if you want to know the type of something in Python, it's a dynamic language. We haven't declared that name as a string, we just set the value. So if we wanna know what type is, we call the type method, and we pass name into it, it'll hopefully tell us that the class is a str.

The other useful method in the wrapper is dir. So if we call the dir built-in method, and we pass name, we're gonna see a whole bunch of stuff. What this is, ignore the stuff that starts with the underscores, what this is, is a directory of every method available on string types.

So if you forget what something is called, it's always just right there for you in the REPL. So let me try one of these, I can say name.upper(), and it'll return that for me. The last very, very useful REPL,
>> Nina Zakharenko: Command is help, if you're ever feeling lost, or not sure what a method does?

You can always type in the built-in help, and either parse in a type or even a variable. So if I put, oops, sorry, my mistake, you have to parse in a type, here not the name of a variable. So when we used type earlier, we saw that the class was str.

So if we did help(str) and press Enter, we'll see this whole thing come up, and this is all of the help for all of the methods. To quit out of the screen, press Q. You could also pass in, you can pass in the type and a particular method, to get the help for just that.

So earlier, I used the upper method. So if I pass in str, which is the type, and then .upper() to help, it'll just show me the help and the documentation for that one method. And what this method does, it returns a copy of the string converted to uppercase.

Okay, so if you ever feel like you're getting lost, you forgot what arguments a particular methods takes, type, help, and dir are your best friends.

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