r/CodingHelp • u/learning_behaviour • 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.
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 variableSo 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
1
u/A_Philosophical_Cat Sep 16 '20
It seems pretty standard for a university course. Maybe on the faster end of normal, but not unusual.
0
Sep 16 '20
[deleted]
1
u/learning_behaviour Sep 16 '20
The part I'm finding difficult with coding in general is everything seems to be taught to us as "if you do this you get x as output", whereas for me to get a full understanding I need to know why. Whereas the course or places I've looked online only show the "what" as opposed to the "why". Does that make sense? Like if it was full explained to me, I should be able to explain it to a 6 year old if I fully understand it. That's how I measure my knowledge at a topic, if I can explain it in the most basic terms and it still makes sense.
Like if you tell me int(5) gives a number just because that's what int() does, I won't get it like the functions I'm struggling with today. Whereas if you explained int means integer hence gives a number. I now understand why we use int() and can use it myself. Whereas stuff like functions haven't been explained in a way I understand. I understood the first 2 days as it everything was explained and made sense such as variables and dotnotations etc. Kind of like simple algebra. I could write the code I learnt so far from yesterday easily on my own. However since starting the module relating to functions, I have only the slightest idea what's going on. I can't code it from scratch but with hints or templates I can edit to make it work after trial and error. As I said earlier, I seem to learn best when reverse engineering code as I can see what input gives what output as I edit and run the terminal.
0
Sep 16 '20
[deleted]
2
u/learning_behaviour Sep 16 '20 edited Sep 16 '20
I have read everything you said and I agree. I have noticed I lean towards trying to type out my own code entirely so I figure out and then in future I don't need Internet or templates. I don't find the personal satisfaction of using others work but I do use templates when trying to understand concepts. I get a written piece of code demonstrating what I'm trying to learn then I reverse engineer it adding different problems and taking away certain code to see what happens, then I get an understanding why this does that. Then I open a new file and start to write it all by myself from what I know to test what I myself know without anyones help.
Sometimes I can get errors and I notice why and figure it out quickly whereas there are times I try to fix it but end up writing loads more lines and making the errors worse and multiply. Then I figure out where I went wrong to start with, delete it and start again so it actually works my brain. I've noticed alot of my peers work look the same with a general template forming their core where it looks similar whereas mine looks shorter and in my opinion much more efficient whilst running the exact same operation in the terminal.
I'm learning slower than the class I think but I'm trying to learn concepts properly without Internet or help. Is this a good approach to learning code from your view or will my slow pace trying to learn how type out my own entire code using the concepts we are learning? I mean even the course tutor said if your stuck just Google the answer and I thought lol what? I thought it's a developer course from a university to learn coding whereas people seem to be okay with using others code templates to pass as actual coursework. Me, on the other hand am trying to use others codes as a means to learn from. Editing it to figure out what strings do what, then trying to shorten it so it's more efficient, straighten out any bugs and finally writing my own piece from scratch to solidify my understanding of it. Does that make sense? BTW I don't mean I learn offline, I mean when trying to get to grips with the code I take a hands on approach rather than look for solutions online. But if I'm totally stuck I'll look for the solution but then won't understand it as I've not figured it out myself like the functions today. I don't mean functions in the way you've described in games, but our course tutor didn't really explain it and just mindlessly sort of wrote code and didn't explain the whys behind it. So if I wanted to do the activity I would have to use the same format of code I copied from the course and type that out over and over. Im struggling with the def bit and how it relates to functions e.g.
Def hello_world():
global hello_world() If xxx Print " yyy" Elsehello_world()
What is the def there for and what does it mean? Same with global? The example I've just given is what the course today showed. Loads of code in that sort of style in python and I had no idea what's going on because there was no proper explanation, just do it because that's how you do it. And when there's multiple use of def for different variables I get confused how the code runs in a uniform chronological manner (top down), because from what I've learnt in 2 days code updated as you wrote more lines e.g
print("hello") print("hello 1")
The output would be the second one, whereas since the introduction of what I wrote above, it seems to jump around to get functions from all over the place and I lose track.
// Also, is this "cargo cult" effect big in the coding world, is trying to write your own piece of code seen as some sort of try hard or something? I don't understand I thought coders type out everything from scratch but from what I've seen so far majority just copy paste from previous work like a jigsaw puzzle and then move on.
1
u/mikedensem Sep 16 '20
def is short for ‘define’ as in, here i will define a function with this unique name and this set of parameters that you can pass to me. I think you are getting hung up on the language itself. A language is just a set of rules used so that everyone agrees on what it means (in the case of a programming language it needs to be understood and ‘interpreted’ by a computer). Try instead to just accept the language and focus on what it is trying to do. Programming is a very abstract concept that takes time to get your head around. If you stick with it you’ll start to see familiar patterns that will eventually click for you.
11
u/Zymoox Sep 16 '20
In my opinion, jumping to functions early on is not unusual. Some prefer to do conditions and loops before, but it's up to the teacher which one to teach first.
Nevertheless, If you feel like the pace of the course is too fast, would you be able to speak with the teacher about it? Alternatively, consider using additional online resources to keep up with the content.