Question about the Nile project, Intermediate Python

I have a question regarding said project.

Link to project:

I am confused about question 12:

First calculate the driver_time for each driver by multiplying driver.speed by distance .

What is driver.speed in reference too? I thought it was calling the method from the driver class, but there is no (). What specifically is the .speed in reference too?
I understand driver is the variable for the iteration of the drivers list, but don’t understand where the .speed comes in.

Can anyone tell me if this specifically has been covered by the python coursework? I am having trouble finding any info.

Any help is very appreciated.

speed is a ‘property’ of the driver class. If you pop over to you’ll see the Driver class is initialised with two variables; speed and salary.
This is one way of accessing those values, and as you’re accessing the variables directly you don’t need the ( ).
Another way of doing this is to set up getter and setter methods. So, you could have something like;
def get_speed():
return self.speed

in the class.

As this is a method (a function in a class) you’d need the ( ) when calling it.
so, in this case;

a = driver.speed


a = driver.get_speed()

would do the same thing.

hope that helps


Thank you so much!

Do you happen to know if this was covered in any of the curriculum? I looked through classes section in beginning python and couldn’t find it. I’m sure it is in there somewhere.
Lots of information, hard to remember it all.
Again, thank you, you have helped me a lot and I am very appreciative!
Be well!

1 Like

No worries.
I can’t remember where/how it was covered, but it did take me a while for it all to click.
As you say, sometimes there’s a lot of stuff to take in, then you get to the projects and it’s like ‘wait… what?’
But, we get there in the end!

Have fun

1 Like

Reading back over your explanation and you explained it perfectly. After I read it a few times I understood exactly. I belive it may be found somewhere in the init section of the coursework, but regardless, your explanation cleared it up and helped me to understand.
Very much appreciated!
Been at this for about a month now and really enjoying it very much!
Be well!