python call def code example

Example 1: how to define function in python

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

example()				#And this is the commands being run

Example 2: python functions

# first we have to write 'def'
# then our function name followed by ()
# and a ':' abd defining  block of code

def multiply():     # naming convention could be same as variable for functions
    product = 10.5 * 4
    return product


product = multiply()
print(product)

Example 3: how to call a function in python

def func():
  print(" to write statement  here  and call by a function ")
  
func()
// Returns

Example 4: how to define functions in python

def add(number):
  equation = 5 + number
  print(equation)
  
 
add(10)

output:
  
  15

Example 5: functions in python

#Functions
#Functions are followed by the 'def' keyword
#Name your function
def myfunc():
  a = 'This is a func'
  
#Calling the function  
myfunc()
print(myfunc())

Example 6: python def

#Use this to shortern a task that you may want to repeat
#Used for making custom commands
def paste(a, b)
	for i in b:
    	print(a)
      
      
while True:
  paste("Python is Cool!!!", 3)
  
#Output:
#Python is Cool!!!
#Python is Cool!!!
#Python is Cool!!!





## - ANOTHER EXAMPLE - ##





happy = "NEUTRAL"

def yes():
  happy="TRUE"
  print("Thank you!")
  
def no():
  happy="FALSE"
  print("That's not nice!")
  
answer=str(input("Do you like my new shoes?   (y/n)  ")
if answer=="yes" or "y" or "Yes" or "Y" or "YES":
  yes()
elif answer=="no" or "n" or "No" or "N" or "NO":
  no()