Python Tutorial 16: Understanding Python Functions
HTML-код
- Опубликовано: 1 ноя 2024
- You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
In this video we show step-by-step instructions on how to use python functions. I do not assume you are an expert, so these lessons are designed for complete beginners.
#Python
#Lessons
#Programming
I ended up watching and working through the examples in this video three times before I felt like I understood it well enough to attempt the homework. I worked out the code by hand in a notebook before entering it into the VSC environment. It took a little bit of code testing before I finally understood how information gets passed between the function and the program but I'm pleased as punch to tell you that I AM LEGEND. I appreciated the bit you said at the end about nipping code from previous efforts because that's exactly what I did and it felt like just the right amount of work even without reinventing the wheel!
It took me a long time to begin to wrap my head around functions because it felt like there was so much going on, but I think I finally understand them. I just finished the homework! Great lesson Paul!
Just a suggestion for everyone: at this point in time I installed some extensions in VSC that makes coding much more efficient like 'Prettier', 'Bracket pair corolizer'. I also changed the color of the cursor and the line number on the left side and the left bar(?). This makes everything stand out, and the changes that can be applied are limitless. Also made shortcuts to clear the terminal and run the program with their own specific keyboard button. I encourage you to try extensions :). Now on with this tutorial, thanks Paul, Cheers all !
which extensions do you suggest and where can we find them? Thanks
Folding lawnchairs having been kept at bay yet again, the legend continues. Thanks, Paul.
THE LEGEND CONTINUES! Good Job, Boyd
Hello Mr.Mcwhorter, Now i am following you for a while and i am grateful to you for providing such quality content for free, Your videos has made me fall in love with electronics and programming.
I'm a student but when i get my first paycheck, it will be dedicated to your patreon.
Thanks again sir, You're the coolest :)
Best of luck!
Mr Mcworther: As usual, thank you for your passion an lessons. Given your background, we know you do not need any money for yourself. We believe that you are probably using those patrion resources to help people in Africa. If so, I admire you even more. Thank you.
Another great lesson and homework assignment, really got me thinking of the best use for these functions, I made a print function to print the arrays of names and grades so I could pass the entered lists and then after my sorting function use the same print function but passed the sorted arrays big smiles from me when it all works. A mistake is only an error if it remains uncorrected.
Fantastic!
thanks, Paul.. that was indeed FUN... a bite size chunk of Python Code... to chew on and digest,. The Function definition, call, and return .. COOL..
Hello Paul. Thanks for your lessons. I have done the homework of lesson 16.
Excellent!
Catching up on these lessons, great to be back after a couple of weeks off. This is another fun one, starting on the assignment now.
In order to avoid an unexcused absence, we will need a note from someone. A doctor, your mom, someone, but we will need a note.
@@paulmcwhorter man you are strict 🤣
Another homerun! Great Lesson. It's a really great explanation for students. Clear and concise. I'll be sending the class here for extra help. Thanks Paul!
Thanks Paul! Great lesson, and great homework assignment!
if you want to disable popups do this:
1.go to settings
2.in search settings panel type hover
3.the hover settings should display
4.then turn off hover enabled
Enjoyed this lesson. Good job covering the scope of variables. The homework will be a bit of fun. See you next week.
Have fun!
Very original way of coffee consumption. I like the glass.
is it a coffee shop or ????
OK I was on vacation and just got to this. Finished the assignment (including the sort grades function) and it works! However, it does not seem all that neat or readable so I can't wait to see how you do it in Lesson 17.
Great job!
phew... the 'in class' homework was a bit of a struggle.. working out how to append .. but got it done .. and completed the homework too... enjoying the lessons... thanks, Paul... God bless...( ooops,.. this comment belongs to an earlier lesson .. #14, I think .. ) looking forward to THIS lesson...
Fantastic!
I did mine differently but it worked just as well. Instead of using two arrays in "parallel", I used only one array where each element is a name and a grade. After reading the array back using the 'pickle.load()' function, I used the 'len()' function to determine how many elements are present.
Great Lesson! Thank you.
@paulmcwhorter Paul, really enjoying your lessons. Can’t thank you enough for paving my coding journey. Re this video….
Was wondering on the significance of using range method in for loop as opposed to simple for i in x type method. Below I’ve posted both methods. They both do the same job but the for i in x: is much simpler.
Range method…
digits=5
num=[2,4,6,8,10]
def sum(x,y):
tot_num=0
for i in range(0,x):
tot_num+=y[i]
print(f'Using for loop range, Total of {y}: {tot_num}')
sum(digits,num)
Other method…
def sum_2(x):
sum = 0
for i in x:
sum+=i
print(f'Sum of x: {sum}')
sum_2(num)
Is using the range method purely for teaching or is it better?
Cheers!
sir currently I am watching your arduino tutorials and you teach really awesomeeee
Glad to hear that
Sir, you are a machine. Love it 💥☕
Great lesson!
Hope your going to include list comprehensions in your tutorials Paul!You could do this function in one line (I haven't used an input in one before but I don't see why not!)
return [float(input("Enter your number")) for i in range(nums)]
Would do it.
Ps keep up the excellent work!!!! I just finished my first year of Electronics and Software Engineering. Your always insuring me!
Really fun.. Enjoy a lot as usual. Thank you sir.. Be safe and take care in this pandemic because you are looking affected with little cold and caugh. Take stream of hot water.
Actually allergies. This was recorded some time ago, I am fine
It would be awesome if you would create a practical Git & GitHub tutorial. 🚀
Thanks a lot for your contribution 🙏🏻
I'm curious to find out why the print operation that is inside the function is displayed when we run the main code. I thought the function only returns the variable z, and the print(afun) and print(bfun) are not assined to z.
I love the videos!! Excited to learn!! God bless the multiverse!
More to come!
Amazing. Thank you.
Thank you Sir, another great lesson! Your lessons are not wasted time (#NWT) for me and that is exactly what I want! 👍
see mine too. The playlist contains almost all the fundamentals of learning Python. Hope the tutorials and source files will be helpful. There is another playlist in the channel, R beginning course.
Please include list comprehensions in one of your lessons. It is a crucial topic which I don't know. Even though I tried going through some online stuff, but was not able to get a hang of its working
Good tutorials sir
Glad you like them!
Great video
"...or die trying"
I like the method of this man, subscribed.
ps: method is a joke :D
Is there a way to take all myNum values in one line then listing them out in append rather than continuously asking for an input in time?
def like(a,b):
z=a+b
return z
name=('Paul McWhorther - ')
gratitude=("Thank you")
sentence=like(name,gratitude)
print(sentence)
I think i got the assignment all correct.
Can't thank you enough ^^.
You are the legend ^^ ....
I love you paul
Thanks!
I assume Paul is teaching with a simple editor and no packages so that we understand Python before installing packages. I went through a four hour tutorial that was supposed to teach Python. In there I followed and wrote a rock, paper, scissor game, and at last a blackjack game. Both functioned after hours of staring at the screen looking for something different on mine than his. I really could not figure out the logic of either game. After a week and a half here I think I could look and figure what in the world happened in those games to make them tick.
Great 👍
As always I learned alot, but I do have a question. Is there not a method or function in python to return the length of an array/list? If not, Is there a way to find out programmatically?
There is, I am sure Paul will teach it soon, but you can use len(x), if it is an array I think it will give the amount of items in there, if its on a string I think it returns the amount of characters.
I am a bit rusty but that should work
@@TroyCroatto This is very true, but pretty sure Paul is staying away from these on purpose, so people think about solving these things manually and get a better learning experience.
Check his for loop video, I think you can figure out by yourself or check my solution:
counter=0
fruits=[1,7,"apple","orange"]
for i in fruits:
counter=counter+1
print(counter)
This for loop is not using "in range(...)", instead it goes through the loop for each item in the array. So if you add 1 to a variable inside the loop, you will get the length of the array. (Don't forget to initialize the counter to 0 before the loop)
Please introduce cyber security tutorials, thanks.
What do you think he is? An encyclopedia?
@@alejandroperez5368 He's a man of God and therefore capable of being more than an encyclopedia
Interesting. Actually, it seems, that pickle is extremely bad security wise.
I Am Legend!
I am surprised that worked as y was not declared an array as in y[ ]
I get it now but haaa!, coding is really something 😅
Chai latte this time. I'm sorry, I hope I won't get a ban 😄
Hope you dont have sugar in that chai. That will get you banned!
@@paulmcwhorter If the bartender put sugar in my chai latte, that could be considered a sabotage I guess!
I played this one 3 times and I found it a little confusing
def add(x,y):
x+y
I did'nt understand why he write return z 8:32
I am legend. I have completed and posted my homework for this lesson. I finally broke down and added a screen capture and webcam element to my video. Please advise if anyone notices that the image of the guy in the camera damages your monitors, glasses, retinas, etc. The link for this is :
ruclips.net/video/84CpCE9FrKM/видео.html
And now we know what you look like! Thats the best part, I like seeing the faces behind the comments.
I m legend
hello Paul please check your email. I am having some droughts