Defining Functions

Description

To define a new function in Sage, use the def command and a colon after the list of variable names. Notice that after the definition of the function, the code is indented.

Sage Cell

Code

def is_even(n):
   return n%2 == 0
is_even(23)

Options

None

Tags

Primary Tags: programming

Secondary Tags:

Related Cells

None

Attribute

Permalink:

Author: Sage Tutorial v7.6

Date: 07 Jul 2017 15:04

Submitted by: Tom Judson

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License