How to the def command
How do you do the def command that makes it repeat code and can make slight differences in python coding?
Voters
Coder100
A good example of this would be something like:
def greet(person): print("Hello %s!" % (person)) greet("Coder100") greet("Taiga") greet("someone else")
it will save you from a lot of typing!
Taiga123m
This is my code but I forgot how to define the varible also what does import random do???
import random Afk2 = turtle.Turtle() Afk2.speed(18) def repeat(Afk2Code): print(Afk2) + (Afk2Code)) Afk2.color('white') Afk2.forward(168) Afk2.left(90) Afk2.pencolor('cyan') Afk2.begin_fill() Afk2.color('red') Afk2.circle(100,180) Afk2.end_fill() Afk2.left(90) Afk2.pendown() Afk2.forward(100)
TsunamiOrSumth
sorry about my last answer, i read the question wrong. could you specify?
Kookiez
@TsunamiOrSumth get on the kookie repl plz
TsunamiOrSumth
@Kookiez i gotchu
Taiga123m
@TsunamiOrSumth its like a python def code that repeat code
TsunamiOrSumth
@Taiga123m for loop?
Taiga123m
@TsunamiOrSumth yea that yea
TsunamiOrSumth
@Taiga123m
for i in range(3): print('peepee')
Taiga123m
@TsunamiOrSumth thanks but what about with turtle???
TsunamiOrSumth
@Taiga123m should be same thing. just make a python repl and import turtle.
The def is basically a function. So it defines what you are writing. Like this:
Like that, functions are useful,instead of repeating code, you use the function name. you can learn more here:
https://www.w3schools.com/python/python_functions.asp
https://www.tutorialspoint.com/python/python_functions.htm