簡體   English   中英

調用方法的正確方法是什么?

[英]What's the correct way to call method?

有人可以解釋為什么下面的代碼會引發錯誤嗎? 我知道如何讓它工作——在代碼的最后一行bob.mainloop()必須用turtle.mainloop()替換,這讓我感到困惑。 為什么它會拋出錯誤Turtle object has no attribute mainloop但是當我用 turtle 替換 bob 時就可以了?

import turtle

bob = turtle.Turtle()

bob.forward(100)

bob.mainloop()

從您的問題來看,似乎mainloop模塊turtle.bob的 function 是Turtle.Turtle 類型turtle.Turtle ,這是不一樣的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM