Paul Manta
0
Q:

how to define functions in python

def example():			#This defines it
  print("Example.")		#This is the defined commands

example()				#And this is the commands being run
17
def function_name():
  pass
2
def add(number):
  equation = 5 + number
  print(equation)
  
 
add(10)

output:
  
  15
  
0
def a_function(input1):
  return input1 * 2
0
# Example 1
def example_function(arg0): # create function with argument
  
  # print the argument gained from executing the function
  print(arg0)
  
example_function("hello") # execute function

# Example 2
def new_function(arg0=None): # create function with argument
  # arg0 = None : allow optional input
  
  if arg0 == "hello": # compare arg0 to "hello"
    return True # if comparrison success
  # return boolean values, ending function
  return False # if comparrison failure

check = new_function("hello") # get boolean value from function
-1

New to Communities?

Join the community