简体   繁体   中英

What's the correct way to call method?

Could someone please explain why the code below throws an error? I know how to make it work - in the last line of code bob.mainloop() has to be replaced with turtle.mainloop() and this is what confuses me. Why does it throw an error Turtle object has no attribute mainloop but when I replace bob with turtle it's ok?

import turtle

bob = turtle.Turtle()

bob.forward(100)

bob.mainloop()

From your question, it seems that mainloop is a function of the module turtle.bob is an object of type turtle.Turtle , which is not the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM