Introduction to Python
  • Introduction
  • Preface
  • Background
  • Installing Python
  • Getting Started
  • Basics
    • More Printing
    • Strings
    • Numbers
    • Exercises
    • Comments
  • Variables
    • Operators
    • Type Conversion
    • Exercises
    • A Brief Introduction to Lists
    • Game Exercise
  • Human Input
  • Functions
    • First Functions
    • Why Functions
    • Exercises
  • Indentation
  • Decisions
    • Booleans
    • Logical Operators
    • If Statements
    • Elif and Else Statements
    • Exercises
    • Rock, Paper, Scissors
    • Game Exercise
    • Game Exercise 2
  • Lists
  • Loops
    • For Loops
    • While Loops
  • More Data Structures
    • Tuples
    • Dictionaries
  • Pygame
  • Extra Content
    • Computers and Code
    • More About Python
    • For Loops with Range
    • List Slicing
Powered by GitBook
On this page
  1. Functions

Why Functions

Functions are a great tool for us for the following reason (and more):

  • Breaks down the code into smaller parts

    • Makes it easier to solve a problem when writing code, and easier to learn when reading code

  • Code reusability

    • Once we define a function and it works, we just need to call the function to get the results. This way we don't have to copy and paste code when want to do a task in multiple places

  • Keeps unnecessary details away from developer

    • Let's say you wrote a function that converts your weight from lbs to kg. If I were to use your function, I'll just call the function in one line. I don't need to see how you coded that function, by being able to call it I can just focus on my code and not think about yours

PreviousFirst FunctionsNextExercises

Last updated 6 years ago