DEV Community

John Mark Bulabos
John Mark Bulabos

Posted on

Third Steps in Python: Fun with Functions and Cracking Conditionals

Greetings, my dear dummies! Back for more, I see. I’m thrilled to see you've survived the loops and lists, and didn't get lost in the Python wilderness. Now, with a bit of coding confidence under your belt, it's time to conquer the next two Python pillars - Functions and Conditionals. Sounds serious, right? It’s not. Well, not as serious as running out of coffee on a Monday morning.

1. Functions - Your Coding Shortcuts

A function is like your favorite recipe, packed neatly into an easily reusable form. Write it once, use it again and again. Just like the secret recipe of grandma’s apple pie, but with less apple and more code.

Here's how you make a function:

def my_function():
  print("Hello from my function!")
Enter fullscreen mode Exit fullscreen mode

And here’s how you use it, or as the techies say, “call” it:

my_function()
Enter fullscreen mode Exit fullscreen mode

Now your function is out there, saying hello to the world. It’s a little bit like sending your child off to their first day of school. They grow up so fast, don’t they?

2. Conditionals - Making Decisions, Python-Style

In Python, as in life, you often have to make decisions based on certain conditions. Is it raining? Take an umbrella. Out of coffee? Cry. That’s the essence of conditionals.

In Python, we use if, elif (short for 'else if'), and else to make these decisions. Here's an example:

weather = "raining"

if weather == "raining":
  print("Better take an umbrella!")
else:
  print("Enjoy the sunshine!")
Enter fullscreen mode Exit fullscreen mode

In the above scenario, Python's going to tell you to take an umbrella because it's raining. Always looking out for you, Python is.

3. Patience and Practice

By now, you’ve probably realized that learning Python isn't a sprint; it's more like a long game of snakes and ladders. You’ll climb up the ladders of understanding and occasionally slide down the snakes of confusion. But that's okay! Every snake slide is a chance to learn something new.

Until We Meet Again…

That's all for today, fellow dummies. Next time, we’ll play with Python's building blocks – Data Structures. Imagine Lego blocks, but less painful when you step on them.

In the meantime, try writing some functions and conditionals of your own. Get creative! Remember, Python is not just a language, it's a journey. And every line of code you write is a step on that journey. So keep coding!


Did this guide help? Share it with your friends, family, and neighborhood coding enthusiasts. Don’t forget to subscribe for more thrilling Python escapades! And remember, I'm always here to navigate the Python wilderness alongside you.

P.S. No dummy was harmed or exposed to real snakes during the creation of this content. Always remember, real snakes are not to be trifled with. Especially if you've forgotten your umbrella.

Top comments (0)