making a function in python code example

Example 1: how to make a 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
!
'''

Example 2: create function in python

def myFunction():
  print('I am running in a function!')

Example 3: python functions

def chess_piece(piece_name, piece_value, piece_rank):
    """Info about a chess piece."""
    print(f"\nThis chess piece is called the {piece_name}.")
    print(f"It has an approximate value of {piece_value} points.")
    print(f"In other words, this piece is the {piece_rank} valuable piece.")
    
    
chess_piece('pawn', '1', 'least')
chess_piece('knight', '3', 'second to last most')
chess_piece('bishop', '3', 'third to last most')
chess_piece('rook', '5', 'third most')
chess_piece('queen', '9', 'second most')
chess_piece('king', 'infinite', 'most')

Example 4: python funtion

def nameOfFunction(something):
  	return something

Example 5: how to call a function in python

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

Example 6: how to define functions in python

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

output:
  
  15

Tags:

Cpp Example