We're trying to make the turtle color be coral and came across this.
from turtle import Turtle, Screen
# case 1: assign variable
foo = Turtle()
foo.shape("turtle")
foo.color("coral")
Screen().exitonclick()
# case 2: use it w/o assign
Turtle().shape("turtle")
Turtle().color("coral")
Screen().exitonclick()
# case 3: methods directly in the module
from turtle import *
shape("turtle")
color("coral")
exitonclick()
case 1 = case 3
In case 2 the color()
method only fills part of the turtle.
In a more general scope,
class Object():
def __init__(self):
print("object created")
def introduce(self):
print("I am an object")
def sleep(self):
print("I am sleeping")
# case 1
foo = Object()
foo.introduce()
# case 2
Object().introduce()
Here, case 1 & 2 are the same.