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

Using the Person Class in the REPL

00:00 In the previous lesson, you inspected the Person class in the person.py file. And in this lesson, it’s time to test the code. Make sure you save your code and then open up your REPL in the directory where your code is saved.

00:16 So where the person.py file is saved.

00:20 So from person (in lowercase), because that’s the name of the .py file, import Person with a capital P because that is the name of the class.

00:32 And this class was intended to be instantiated, so create an instance of this class. So I’m just going to use myself as an example. You of course can use yourself as an example.

00:42 So my first name, that is a first input parameter. The second input parameter is my last name, and the third one is my age, which is of course 21.

00:55 So that is my instance. The first thing to test is the string dunder method. And as you might know, what the string dunder method allows you to do is to apply the str() function to your instance.

01:10 So str(Steven) indeed gives me, “Steven Loyens is 21 years old.” So it gives me the value of first_name, which is Steven, the value of last_name, which is Loyens, and the value of age, which is 21, and it returns the f-string.

01:30 The method in the class was called .as_tuple(). And let’s apply that method to the instance. So Steven.as_tuple(), don’t forget the parentheses, and indeed you now have that returned as a tuple.

01:47 So the code is working fine. So you have learned that you can use the dunder .dict attribute as any of the dictionaries. So for example, in line 13, you can apply values to it and in the string dunder method, you can just access that dictionary using the normal square brackets methodology.

02:08 So now you know you can inspect the .dict dictionary, you can also retrieve values from it. But can you make changes to it in runtime? Yes, you can.

02:18 You’ll see that in the next lesson.

Become a Member to join the conversation.