Skip to Main Content
Python Essentials For Dummies
book

Python Essentials For Dummies

by John C. Shovic, Alan Simpson
April 2024
Beginner content levelBeginner
192 pages
3h 46m
English
For Dummies
Audiobook available
Content preview from Python Essentials For Dummies

Chapter 8

Wrangling Bigger Chunks of Code

IN THIS CHAPTER

Bullet Creating your own function

Bullet Including a comment in a function

Bullet Seeing how to pass information to a function

Bullet Returning values from a function

In this chapter, you learn how to better manage larger code projects by creating your own functions. Functions provide a way to compartmentalize your code into small tasks that can be called from multiple places in an app. For example, if something you need to access throughout the app requires a dozen lines of code, chances are you don’t want to repeat that code over and over every time you need it. Doing so just makes the code larger than it needs to be. Also, if you want to change something, or if you have to fix an error in that code, you don’t want to have to do it repeatedly in a bunch of different places. If all that code were contained in a function, you would have to change or fix it in only one location.

To access the task that the function performs, you call the function from your code, just as you call a built-in function such as print. In other words, you just type the name ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Essentials For Dummies

Python Essentials For Dummies

John C. Shovic, PhD, Alan Simpson
Introduction to Python

Introduction to Python

Jessica McKellar
Python for Data Science For Dummies, 3rd Edition

Python for Data Science For Dummies, 3rd Edition

John Paul Mueller, Luca Massaron
Python for Excel

Python for Excel

Felix Zumstein

Publisher Resources

ISBN: 9781394263479Purchase Link