0
How can i access a variable declared inside a method?
Here..wen i tried to print fido.sound nothing happens..even if i called the function bark() in the next line..an error appears..can some one tell me whats happening here? https://code.sololearn.com/cVR7rm5idWuV/?ref=app
4 ответов
+ 5
That's not how it works. This is how it should be:
fido.bark()
print(fido.sound)
+ 7
You need to call the bark() method before accessing the attribute and not after. The attribute will only be created after you run it.
(A variable linked to an object is called an attribute)
+ 1
it works Aymane Boukrouh [INACTIVE]
0
Aymane Boukrouh [INACTIVE] thats what i did
Fido.bark().sound
Called the bark then the attribute..