Welcome to Chapter 6: Functions! 🔧
D.R.Y. stands for Don't Repeat Yourself — one of the most important rules in programming!
💡 Think of it like this: A function is like a recipe. You write the recipe once, and then you can use it over and over again. Instead of writing the same code 10 times, you put it in a function and call it 10 times!
Key parts of a function:
def — the keyword that says "I'm creating a function"# Without functions (BAD — repeating code!):
print('Hello, Alice!')
print('Welcome to CodeRex!')
print('Hello, Bob!')
print('Welcome to CodeRex!')
# With functions (GOOD — write once, use many!):
def greet(name):
print(f'Hello, {name}!')
print('Welcome to CodeRex!')
greet('Alice')
greet('Bob')
Run your code
Welcome, Alice!
Welcome, Bob!
Welcome, Charlie!