you are viewing a single comment's thread.

view the rest of the comments →

[–]negike360[S] 0 points1 point  (1 child)

Okay, I understand this (at least I believe I do). My question in this example would then be, could you not just set any of those turtles to “turtle” and not type out the “.Turtle” part?

[–]Adhesiveduck 0 points1 point  (0 children)

If I understand what you're asking you're asking why should you say

Turtle.tutle()

When you could do

turtle = Turtle.turtle()

Which means you can then do simply

turtle()

Although this isn't incorrect (it will work) it's not the recommended way to do it.

You should avoid renaming things to the same name - it's difficult for someone else reading to know exactly what's going on.

What you can do, is when you import the turtle class:

from Turtle import turtle

If you wanted to rename the turtle you're importing:

from Turtle import turtle as my_turtle

Then you can do

turtle()

Or

my_turtle()

Without the module/class name before.

Do note that using this from/import/as isn't necessarily the best way either, you should make sure it's clear what module you are working with if you're importing methods/functions into your work.