Invent Your Own Command ๐ญ
print(), len(), input() โ you've been using commands somebody else
built. Today you build your own.
A function is a bundle of code with a name. You create one with def:
def cheer():
print("GO TEAM GO!")
print("๐๐๐")
Three things to notice:
defmeans "define" โ you're inventing a new command- the parentheses
()and the colon:are required - everything indented underneath belongs to the function
Here's the surprising part: running that code prints nothing! def
only builds the function, like writing a recipe. To actually run it you
call it by name:
cheer()
cheer()
Now it runs twice. That's the magic: write it once, use it forever. ๐
Your mission
- Build a function called
cheerwithdef cheer(): - Make it print at least 2 lines
- Call it 3 times below the function
Your code
Press โถ Run to see what your code does!