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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Go Interactive

Whether you’re learning about basic Python data structures (strings, lists, dictionaries, and so on) for the first time, or you are debugging an application, the interactive Python shell will be one of your best learning tools.

To use the interactive Python shell (also sometimes called a “Python REPL”), first make sure that Python is installed on your computer. To activate the interactive Python shell, simply open your terminal and run python or python3, depending on your installation. You can find more specific directions in First Steps With Python.

00:01 Go Interactive. The Python shell, or REPL, is a great way to instantly examine and create code. If you haven’t used it before, you’re going to see a quick introduction to it now. So, here you are in the command prompt or terminal, and to launch Python you either type python or python3 depending on how your system’s configured.

00:28 And here you are in the Python shell. You can create variables in the normal way,

00:40 but one thing you may not be aware of is you don’t need a print statement to see the result of what you do in the REPL. Here, if I type a + b and hit Enter, it gives us the result straight away.

00:56 One useful part of this is you can see the difference between a str (string) and an int straight away. So if I just hit a, here at the moment, we see 7.

01:05 But if I make a into the string '7' and type a again, we can see straight away that it’s a string, meaning we’re less likely to get confused as to whether we’re dealing with a number or a string.

01:21 As you’ve seen, it’s quick and easy to create code in the Python shell, but you can also use it to discover and explore the methods that are available to you. Now you can see this in action.

01:33 An important part of learning Python is understanding the methods which are available to you on objects that you’ve created. So for instance, in the case of strings, as we’ll see here, there are a number of methods which allow you to manipulate the string quickly and easily without you having to create that method yourself. Now you’re going to see that in action. Firstly, create a string.

02:00 Then next, to find out what methods are available, use the dir() command with the object inside the brackets. There, you can see a list of the methods which are available for that string.

02:15 Don’t be concerned about the ones which have double underscores (__) at the beginning. These are often called dunder methods, and while they’ll be important to you later on in your career, for the moment, don’t you concern yourself too much with them. However, there are quite a few useful methods, as you can see towards the end of the list.

02:35 One we’re going to take a look at right now is .upper(). This capitalizes the string, so just applying a.upper() gives us a capitalized version of the string.

02:51 Another one is .split(). .split() splits the string on a character that you choose. If you don’t give it one, it will split that string on a space (' '). So here, we will see it will return a list…

03:09 of 'hello' and 'there'. These built-in methods can be really useful, and it’s important to know what’s there so you don’t waste time duplicating something which already exists within Python itself. Remember, you don’t have to create an instance of the object to see what it can do.

03:27 So, here we can do dir() and then int, and we can see that mostly it’s those dunder methods, but there are a few available to us. And let’s have a look at float.

03:47 And see, similarly there, mostly they’re dunder methods, but there are a few available which you can make use of straight away. Another important part of the shell is that you can obtain help using the help() command. Now let’s see that in action.

04:04 Having access to help() about Python commands and functions is really useful, and it’s accessed really easily, just with the word help().

04:15 We put the object in question we want—in this case, int—and then hit Enter, and we’re taken into the help viewer. So we can see here that int is an object, and if we scroll down using the cursor keys, we can see that there are methods defined and you can see all those dunder methods, which we saw earlier on. If you want to move down faster, you can use the Spacebar to move down a screen at a time,

04:42 and B moves you backwards a screen at a time. When you’ve found the information you want, press Q to quit back to the Python shell.

stennow on April 2, 2020

in the:


example how did you go back (or up if you like). Hitting “space” does skip a hole page at the time, but hitting “d” key did not go back for me. I have tried small d and capital d shift d and control-d and even tried it all with “b” also in case i heard wrong. but it does not work for me?

python 3.8 shell through CMD windows 10.

Regards René

vkvn on May 1, 2021

Hello Rene,

The keybindings seem similar to VIM, so I am not sure if it works on Win10.


Become a Member to join the conversation.