What is a 'procedure' in Python?

QuestionsQuestions8 SkillsProDec, 22 2025
0131

In computer science, a procedure is a set of instructions designed to perform a specific task without necessarily calculating or returning a specific result for the program to use.

While Python uses the keyword def for everything, people often distinguish between a "Function" and a "Procedure" based on how they behave:

1. Function vs. Procedure

  • Function: Its main goal is to calculate a value and return it (like a calculator).
  • Procedure: Its main goal is to perform an action (like printing, saving a file, or moving a character in a game).

2. Example of a Procedure in Python

In Python, a procedure is simply a function that does not have a return statement.

# This is a procedure
def welcome_user(name):
    print("--------------------")
    print(f"Welcome back, {name}!")
    print("--------------------")

# We call it to perform an action (printing)
welcome_user("Labby")

3. Key Characteristics of a Procedure

  • Performs "Side Effects": Instead of giving back a number, it affects the outside world (e.g., changing the screen, updating a database, or making a sound).
  • Returns None: As we discussed earlier, if you try to save the result of a procedure into a variable, that variable will be None.
  • Task-Oriented: Use procedures to organize your code into logical "steps." For example, clean_data(), save_progress(), or play_sound().

Summary

In Python language specs, everything is technically a Function. However, developers use the word Procedure conceptually when describing a function that is meant to do something rather than calculate something.

You are currently writing procedures in your arguments.py and keywords.py because those functions use print() to perform an action but don't return a value!

0 Comments

no data
Be the first to share your comment!