'What do the brackets in 'turtle.pen()' do? What are they supposed to contain?
So recently I was planning to write a code using turtle graphics and I had a question. What do the brackets in t = turtle.Pen()
mean? What are they supposed to contain? Please answer in a simplified manner as I am still a beginner at python :)
Solution 1:[1]
The brackets in turtle.Pen()
don't need to contain anything but there are three optional arguments:
shape='classic', undobuffersize=1000, visible=True
There are several other shape
choices (like "turtle"
) and visible
can be False
and showturtle()
can invoked later, if desired.
Don't confuse turtle.Pen()
(an alias for the Turtle
class) with turtle.pen()
, a method which allows you to get/set attributes of the turtle's pen. You used one in your title and another in the body of your question.
Solution 2:[2]
Those aren't brackets, they are parentheses. It's a function call without arguments (or in this case, an object instantiation).
What they're "supposed" to contain depends entirely on the function you're calling (or object you're instantiating).
For instance, print()
accepts the arguments to print (or none to just print a new line):
>>> print()
>>> print("hello")
hello
>>> print("hello", 42)
hello 42
>>>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | cdlane |
Solution 2 |