Function Define

ASnake Documentation

Table Of Contents

Summary:

Functions are blocks of code meant for reuse by being called, and typically accept inputs and have outputs.

Once defined, ASnake will auto-call the function when bare:

myFunction --> myFunction()

When not bare, it may wrap the line, treating everything as arguments. Read more about this ASnake feature here.

Otherwise you can specify the arguments yourself via parenthesis.

Syntax def:

Python's function defines start with a def, and then have the function name. After that, parenthesis which can include the function input parameters the function may expect.

def hello(x):
    print(f"hello {x}")
hello('world!')
# result: hello world!

For a more extensive look at Python's function defines, you can read about them here.

Syntax return:

return will stop the function and give the value after it. This works in both Python's function define and ASnake's function define.

def doubleIt(x):
    return x * 2

print(doubleIt(2) + 2)
# result: 6

Syntax does:

ASnake's function define has the function name first, then `does, and then the block of code. It is much simpler.

hi does "hello"
world does
    "world!"

hello()
world()
# result:
# hello
# world!

For function arguments, you must use from at the end of the function, with all it's arguments after.

doubleIt does
    return number * timesBy
from number , timesBy = 2

print doubleIt(2, 3)
# result: 6
Scroll to top