8FUNCTIONS GIVE YOU SUPERPOWERS

image

Functions are reusable blocks of code that perform specific tasks. Say you want to write code that builds a tree in Minecraft. You could rewrite the tree-building code every time you need to use it in your program (or copy and paste it); however, this would be inefficient, especially if you wanted to change it.

Instead of copying and pasting, you could write the tree-building code as a function. Recall that we used some functions in earlier chapters: str(), input(), and int(). They’re all functions that are built into Python. You’ve even been using Minecraft functions, such as the getBlocks() and setPos() functions, ...

Get Learn to Program with Minecraft now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.