From the course: Python Quick Start

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Defining functions in Python

Defining functions in Python - Python Tutorial

From the course: Python Quick Start

Defining functions in Python

A programmer's main goal is not just to solve problems through coding, but to do so efficiently. When you're programming, you may find yourself typing the same set of instructions in multiple places in your program. When you do this, it not only takes longer for you to write and read your code, but also takes longer for your computer to read and follow your instructions. That's why it's important to be concise. One major way to be concise is to use functions. Functions help you stay organized. Each function has a fixed purpose. In other words, each function is meant to perform a particular procedure. You can write a set of instructions needed to perform a procedure and store it in a function. So whenever you want to use this procedure in your program, all you have to do is refer to the function you wrote. For example, let's say my program had this section of code. As you can see, there's a set of instructions that shows up in multiple places. And note the comments that say other stuff…

Contents