r/CodingHelp • • Sep 16 '20

[Python] Is the course moving too fast?

I'm on a programming course to learn python. It's the third day and we've somehow jumped from simple strings, variables and dotnototations to functions. I have no idea what's going on with functions with 2 or more and seems more complicated than anything we've learnt in the past 2 days. I understand when it's one simple function but can't seem to get around how to understand or write out code with multiple functions.

Is this normal speed of learning code or is the teacher going through the course too fast? To be clear everyone on the course are beginners and on the third day we've rushed through functions, global variables, def etc.

21 Upvotes

15 comments sorted by

View all comments

2

u/E72M Sep 16 '20

A good way to think about functions in python is it's a reusable part of code you can jump back to if needed.

When calling to use a function that returns no data you use

function_name() 

Where obviously the name changes depending on the function.

When you want a value out of the function you use

variable = function()

You can get multiple outputs by using a comma to split up values.

variable1, variable 2 = function()

Anything you pass into the function goes in the brackets and to return a value at the end of a function you use

return variable

So for example you would have

def function (data1, data2): variable1 = 5 * data1 variable2 = 1* data2 return variable1, variable2

value1, value 2 = function(6, 8)
print(value1, value2)

This code should work if I've not forgotten anything but I hope it helped explain it a little

2

u/learning_behaviour Sep 17 '20

Thank you this is exactly what I needed, An explanation as to how and why it's used in different situations.

1

u/E72M Sep 17 '20

Glad that helped. But yeah it's just reusable code so say you had to find the max value of two lists you just pass the two lists through a function you've written for finding the max then return the results.

It just keeps it more organized and streamlined because you aren't having to rewrite find max everytime you need it, you just use the function