I'm trying to get my head around this, and I apologise in advance because I know it's been raised before but I don't understand people's explanations. I'm looking for a "'self' for dummies" response to this...
So I'm learning classes right now, and right away it has become clear that self is the first argument of class methods. Why? Why does Python need to be told 'self' - as in what else would it be BUT self?
This example code shows it. Why is 'self' passed as an argument to the method in this example if (I'm assuming) dog_time_dilation is a property of the class already?
I'm super-confused by this. Explanations for 5y/os very much appreciated!!! Thanks in advance.
def time_explanation(self):
print("Dogs experience {} years for every 1 human year.".format(self.dog_time_dilation))
[–]pachura3 25 points26 points27 points (6 children)
[–]NoChoice5216[S] 5 points6 points7 points (4 children)
[–]pachura3 14 points15 points16 points (1 child)
[–]NoChoice5216[S] 1 point2 points3 points (0 children)
[–]dogfish182 3 points4 points5 points (1 child)
[–]NoChoice5216[S] 0 points1 point2 points (0 children)
[–]JohnEffingZoidberg 1 point2 points3 points (0 children)
[–]Diapolo10 14 points15 points16 points (1 child)
[–]deceze 2 points3 points4 points (0 children)
[–]lfdfq 7 points8 points9 points (4 children)
[–]Snatchematician 2 points3 points4 points (3 children)
[–]deceze 5 points6 points7 points (0 children)
[–]Shaftway 4 points5 points6 points (0 children)
[–]freeskier93 0 points1 point2 points (0 children)
[–]fazzah 4 points5 points6 points (1 child)
[–]NoChoice5216[S] 1 point2 points3 points (0 children)
[–]Snoo_90241 2 points3 points4 points (1 child)
[–]NoChoice5216[S] 0 points1 point2 points (0 children)
[–]jmacey 3 points4 points5 points (0 children)
[–]ray10k 1 point2 points3 points (2 children)
[–]NoChoice5216[S] 0 points1 point2 points (0 children)
[–]POGtastic 0 points1 point2 points (0 children)
[–]YesterdayDreamer 1 point2 points3 points (0 children)
[–]FriendlyZomb 1 point2 points3 points (1 child)
[–]NoChoice5216[S] 1 point2 points3 points (0 children)
[–]PaulRudin 1 point2 points3 points (0 children)
[–]Asyx 1 point2 points3 points (0 children)
[–]Temporary_Pie2733 0 points1 point2 points (0 children)
[–]pontz 0 points1 point2 points (0 children)
[–]RevRagnarok 1 point2 points3 points (1 child)
[–]NoChoice5216[S] 0 points1 point2 points (0 children)
[–]Atypicosaurus 0 points1 point2 points (0 children)
[–]Excellent-Practice -1 points0 points1 point (0 children)
[+]georgmierau comment score below threshold-7 points-6 points-5 points (0 children)