Python turtle, using colours from a list -


  color = [turtle color ("red"), turtle colour ("blue"), turtle Color ("yellow"), turtle caller ("green")] fred = color [0], for turtles. (100), Turtle Left (90), color [1], for turtles. (100), Turtle (90), color [2], for turtles. (100), Turtle Left (90), color [3], for turtles. (100), Turtle Left (90)  

Returns the type (color [0]) square, from a list, trying to create a square with four different colors. Can i reach

Your code:

color = [turtle. The color ("red")]

will run the function turtle.color ("red") , and store the return value

It is like doing exactly :

color = [none]

If you have colors [0] you get the return value, not the function. Python does not know that none has expired via function call, or if you have handed it manually.

You have just posted 2 lines of code, so I do not know enough that the context here is, but you may be want to do something like this:

  color = [lambda: turtle Color ("red"), lambda: turtle colour ("blue")]  

What it does, stores a tall (or 'anonymous function') in your list. This function is not executed you will now receive:

  & gt; & Gt; & Gt; Color [0] & lt; Function & lt; Lambda & gt; 0x8008 9e710 & gt;  

And you can execute it several times like this, by adding brackets such as: color [0] ()

This technique is known as 'Currying'.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -