Python Classroom notes 06/Mar/2026

Using functions

  • python allows to call functions by passing arguments
    • postionally
    • named
  • Consider the following function
def add(a: int|float, b: int|float) -> int|float:
    """Returns sum of two numbers

    Args:
        a (int|float):
        b (int|float):

    Returns:
        int|float: Return sum of two numbers
    """
    return a + b
  • Calling arguments by position
add(1,2)
  • Calling arguments by name
add(b=2, a=1)
  • Optional arguments: i.e. arguments with default values
  • Refer Here for the notebook with functions examples added

Create a function

  • Lets write a program which prints n = 3
  *
 ***
*****
  • if we pass n = 5
    *
   ***
  *****
 *******
*********
  • Code
def print_triangle(size=5,symbol='*'):
    index = 0
    while index < size:
        count = 2*index + 1
        space_count = size - index - 1
        print(" "*space_count, end="")
        print(symbol*count)
        index = index + 1

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading