Jason K.
0
Q:

how to use def 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 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 function():
  print('This is a basic function')
  
function()
// Returns 'This is a basic function'

def add(numA, numB):
  print(numA+numB)
  
add(1,2)
// Returns 3

def define(value):
  return value

example = define('Lorem ipsum')
print(example)
// Returns 'Lorem ipsum'

6
def functionName(variable):
  //function content
7

  def my_function(fname, lname):
  print(fname + " " + lname)


  my_function("Emil", "Refsnes") 
3
x ="world"

def myfunc():
    global x
    x ="hello"
myfunc()
print(x)

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