Heather
0
Q:

create function in python

def test_function(argument1,argument2,argument3) :
  # Do something with the code, and the arguments.
  print(argument1)
  print(argument2)
  print(argument3)
  
# Calling the function.

test_function('Hello','World','!')

# Output
'''
Hello
World
!
'''
11
def example():			#This defines it
  print("Example.")		#This is the defined commands

example()				#And this is the commands being run
17
def myFunction(say): #you can add variables to the function
  print(say)

myFunction("Hello")

age = input("How old are you?")

myFunction("You are {} years old!".format(age))

#this is what you get:

Hello
How old are you?
>>11 #lol my real age actually
You are 11 years old!
18
def your_function(arg1, arg2, arg3):
  do_something
  do_something_else

#to call the function (make it run):

your_function(something, something, something)
2
def myFunction():
  print('I am running in a function!')
14
def nameOfFunction(something):
  	return something
6
def my_function(a,b=1,c=2,verbose=True):
  x=a+b+c
  if verbose:
    print('Just wanted to tell you x=%d' %x)
  return x

n=my_function(3)
4
# 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