4. Decomposition, Abstraction, and Functions

  Рет қаралды 237,474

MIT OpenCourseWare

MIT OpenCourseWare

Күн бұрын

Пікірлер: 156
@vi3524
@vi3524 5 жыл бұрын
Jealous of MIT students who can have such an awesome teacher; Thankful to MIT who's willing to share these awesome lectures.
@iitasperiant6102
@iitasperiant6102 2 жыл бұрын
Help bro please 🥺
@鄭心和
@鄭心和 4 жыл бұрын
0:02:30 How do we write code 0:04:15 Abstraction and Decomposition 0:06:09 Abstraction example 0:08:00 Decomposition 0:09:14 Abstraction 0:10:06 Functions 0:11:37 How to write and call/invoke a function 0:14:43​ In the function body 0:15:45 Variable scope 0:18:25 Variable scope example01 0:21:09 One warning if no return statement 0:22:00 0:24:00 ​0:26:25 Functions as arguments 0:28:00​ 0:30:00 0:30:57 Variable scope examples 0:34:18 ​(Link description : Some more Variable scope example) 0:35:44 ​Variable scope example 0:36:21 ​Variable scope example global scope 0:37:41 ​Variable scope example call h() 0:38:45 Variable ​scope example return to g() scope 0:39:41 Variable ​scope example return to global scope
@diogos3475
@diogos3475 3 жыл бұрын
Real Heroes don't wear capes
@petor95
@petor95 3 жыл бұрын
Thank you 🙏🏾
@Billyxiao
@Billyxiao 2 жыл бұрын
Amazing
@SK-qy5nz
@SK-qy5nz 7 жыл бұрын
Thanks MIT for providing equal opportunity for poor people like me. I am grateful to these wonderful courses. Will try to see everything till i die....
@SZ-hg5fd
@SZ-hg5fd 6 жыл бұрын
I immigrated from China to Canada, as you know there’s no KZbin in China, so I am lucky to have such an opportunity to watch MIT courses. I am grateful to all of these!
@jason-ps6mf
@jason-ps6mf 6 жыл бұрын
I am a Chinese from a poor village using shadowsocks to watch this awesome video
@kattetivikram1862
@kattetivikram1862 6 жыл бұрын
Iam indian it is very useful to me .Iam computer science students in india
@MultiDexter92
@MultiDexter92 5 жыл бұрын
Americans, where are you?
@jonathanhansen4282
@jonathanhansen4282 5 жыл бұрын
@@MultiDexter92 Im at a top 15 Uni and am still here....
@jonahcornish6160
@jonahcornish6160 7 жыл бұрын
Wow, this instructor is excellent. She does a great job of comparing what you are coding to simple concepts. I am always let down when an instrucor is really intelligent but makes the material unnecesarilly convoluded to the point you woulld only be able to understand it with advanced knowledge of the subject.
@jakeambrose4294
@jakeambrose4294 7 жыл бұрын
if u plan to keep learning it and like to network with other people who are also find me messaging my facebook page knowledge obsession if trading info and sources and solving problems with others interests u
@tonyravindran
@tonyravindran 5 жыл бұрын
actually in the regular course the reading material and and the slides are shared beforehand for the students to prepare themselves for the lecture but we have to jump straight into the lecture
@aaronisinjapan
@aaronisinjapan 5 жыл бұрын
This is honestly the best explanation of functions in python. Global and local differences are also extremely clear. Great job!
4 жыл бұрын
8:00 modules. Create it once, debug it once and use it many times for different projects or in your code with different inputs.
@rishanVJrathne
@rishanVJrathne Жыл бұрын
Thank You, Dr. Ana Bell . It was a nice explanation of the SCOPE.
@algemmegla9002
@algemmegla9002 4 жыл бұрын
35:40 Scope Details. I think it's helpful to just look at it line by line. At first I got confused with x = x + 1 because it seemed to be inside def h(), but it's actually inside def g(x). def h() is such a simple block of code, that it threw me off at first. Assign x to 3 +1. print the string 'g:x=' , h() assigns x to 'abc', but returns None. So the string, abc, stays within that scope. Calling the function, h() ,returns None. return x is typed "after" print(x) in the order. Brain slowly absorbing. def g(x): def h(): x = 'abc' x = x + 1 print('g: x =', x) h() return x x = 3 z = g(x)
@henrikmanukyan3152
@henrikmanukyan3152 Жыл бұрын
where does h() take its "x" variable if it has neither defined nor had that argument in its definition? is this the case of using global variables that is not recommended?
@ProfitScalpKing1
@ProfitScalpKing1 7 жыл бұрын
Thanks a bunch Dr. Bell
@senshi_ichigo
@senshi_ichigo Жыл бұрын
she is So Kind during Explaining and thanks for that Ana 😀 Greetings from #Morocco .
@DARELASISI
@DARELASISI 3 жыл бұрын
THIS VIDEO IS PYTHON MADE EASY, THANK YOU, ANA.
@mikhailskalyga9386
@mikhailskalyga9386 4 жыл бұрын
If only at my university the programming was teched like that... Idk, if it's just me, but how important the teacher in the teaching process. At my university, the lectures were boring, students were not involved in the process, and in the end, I started hating the programming classes. Now I can see how beautiful and interesting they could be
@user-nm9fk7cb4b
@user-nm9fk7cb4b 3 жыл бұрын
This is only interesting to me because in my own time over the course of years I’ve been putting pieces together of functions within functions that leads to spontaneous, recursive creative syntax Don’t blame your teachers, if you’re bored THEN YOU’RE THE BORING ONE. That also means you know why you’re bored, so you can change it
@Hivlik
@Hivlik 3 жыл бұрын
34:00 what is the difference between incrementing x and printing x? it is defined in the same place relative to g() and h()
@as-br9ov
@as-br9ov 3 жыл бұрын
When you are trying to print it, func g is able to track down x into the global scope and get it. Yet, if you want to convert it into something, in other words if you want to implement process onto x, you have to define it first in whatever scope you are. Then you can modify it.
@goclbert
@goclbert 2 жыл бұрын
Me doing problem set 1: "Man its gonna take me a long time to be able to afford a house"
@GhostkillerPlaysMC
@GhostkillerPlaysMC 5 жыл бұрын
39:49 If the function h() had a return at the end, would the outer function have returned x as 'abc' instead of 4?
@Rollo_and_Jeet
@Rollo_and_Jeet 5 жыл бұрын
only if we assign the return of h() to x like x= h(). Otherwise 4
@algemmegla9002
@algemmegla9002 4 жыл бұрын
21:50 (regarding the section on return and None) When describing remainder = i % 2, it might be easier for beginners to say: i "modulus" 2, instead of i "percent" 2. Overall, the videos are excellent. Thank you! :D
@akbarrauf2741
@akbarrauf2741 7 жыл бұрын
thank you ,mit
@carmenc7251
@carmenc7251 4 жыл бұрын
In the last example, where x is not defined in function g(x) should be giving an error (UnboundLocalError: local variable 'x' referenced before assignment ), isn't it? Like how the example shown in 32:42
@nikhilkolhe2374
@nikhilkolhe2374 3 жыл бұрын
x is the formal parameter, so it well be assigned to the value of actual parameter at function call. So we should not get an error
4 жыл бұрын
4:00 functions: decomposition and abstraction
@GovindKumar-mu6jq
@GovindKumar-mu6jq 3 жыл бұрын
The way she explained about the scope of variables is awesome...
@abdelkarimjaja7740
@abdelkarimjaja7740 5 жыл бұрын
Thanks, MIT for give us this opportunity
@strategoclownery389
@strategoclownery389 2 жыл бұрын
can anyone tell me how she just comments out a hole block of code without doing the """ thing? That would be such a great help. Thanks
@mitocw
@mitocw 2 жыл бұрын
In IDLE, use ctrl + D to comment out many lines of code.
@xuefengwong9097
@xuefengwong9097 6 жыл бұрын
The scope part is clear and easy to understand, thanks!
@leixun
@leixun 4 жыл бұрын
*My takeaways:* Function specification/docstring 13:00
@alirezarezaeikalat9421
@alirezarezaeikalat9421 3 жыл бұрын
tnx MIT for make these courses public
@jakeambrose4294
@jakeambrose4294 7 жыл бұрын
im lost but im just going to keep watching.
@pocok5000
@pocok5000 7 жыл бұрын
I'm not sure that's a good idea. Watch again until you understand. Then you can understand the rest easier.
@LordAhmedAmr
@LordAhmedAmr 7 жыл бұрын
I hope you didn't lose interest by now and that you started to wrap your head around things. if not though i would recommend watching the CS50 course from harverd it's way much easier yet very useful.
@vmalonbc
@vmalonbc 6 жыл бұрын
Re-watch if lost. I have to rewind tough parts a couple of times until I get it. No shame in that.
@idontknow-ms8mc
@idontknow-ms8mc 5 жыл бұрын
Udacity's Intro to Computer Science course is pretty good, as well and goes over concepts very simply. There is also a version of this course on Edx.org.
@MrFaiqueShakil
@MrFaiqueShakil 4 жыл бұрын
@@idontknow-ms8mc It is more complex than this.
4 жыл бұрын
11:53 How you write a function. Parts of a function
@jayholt
@jayholt 5 жыл бұрын
Oh man, missed a good opp to have a func_e. Regardless, loving this content. Makes me miss college 😭
@algemmegla9002
@algemmegla9002 4 жыл бұрын
ha ha. Took me a minute.
@alham9656
@alham9656 3 жыл бұрын
@@theerdalavignesh4443 funky
@demon-godashura1661
@demon-godashura1661 7 жыл бұрын
Well i don't know why but at 27:34 when i pass the same code in my spyder it says "unexpected EOF while parsing"
@rootytuners
@rootytuners 4 жыл бұрын
You’ve probably omitted a closing quote or bracket somewhere.
@peterhind
@peterhind 9 ай бұрын
So when h returns, h in the scope of g still equals 'some code' and None is just sort of floating about in the scope of g. But when g returns, the value 4 is assigned to z because of the equals sign in the code. Is that right ? And if that's right, that means the None in the scope of g was inaccessible. Just trying to get it clear.
4 жыл бұрын
25:00 example of a function "is even"
@masoudelahian613
@masoudelahian613 2 жыл бұрын
The last example about nesting would have been better if you had written h as function of other thing that would have added to x and participate in the main function. BTW it was really a good pedagogical video.
@phildawg91
@phildawg91 4 жыл бұрын
so, x = 3 def f(y): print(x) works but def g(y): x =+ 1 does not work. because it's not in the functions scope. so are only operations with a variable out of scope not possible? because in either case it has to know the value of x, whether you print it or whether you do something with it. so why does the second one not work?
@blackprince3288
@blackprince3288 4 жыл бұрын
Best explanation of abstraction and decoMposition!!!!!
@晃蕩-m6f
@晃蕩-m6f 6 ай бұрын
It's incredibly easy to understand
@Yugandhar635
@Yugandhar635 6 жыл бұрын
when func_a( ) is mapped to z ... then can we write return z instead of return z( ) ?
@nikhilkolhe2374
@nikhilkolhe2374 3 жыл бұрын
no if you do that you are returning the object func_a. but when you return z(), you are returning the value of expression func_a(), which is the value returned by func_a.
4 жыл бұрын
26:03 in python everything is an object
4 жыл бұрын
10:00 recap functions
@percih70
@percih70 7 жыл бұрын
Python tutor is awesome .......
@sd-xk7qr
@sd-xk7qr 3 жыл бұрын
It's great. The only problem sometimes is that it stops at 1000 steps
@Mujahid_Abbas
@Mujahid_Abbas 3 жыл бұрын
Thanks Mam For Upload On U-Tube so That I am able to listen this.
@mustafaadelamer2789
@mustafaadelamer2789 5 жыл бұрын
thank you so much for your illustrations Dr. Ana. Very very useful.
@kushagrakanungo9517
@kushagrakanungo9517 5 жыл бұрын
How come the instructor can remove the comments from the code in one go? What is the command to do it?
@sebastiangutierrez9650
@sebastiangutierrez9650 5 жыл бұрын
highlight the comments and then do ctrl+1
@kushagrakanungo9517
@kushagrakanungo9517 5 жыл бұрын
@@sebastiangutierrez9650 Thank you so much.
@hycopa2447
@hycopa2447 2 жыл бұрын
Thank you MIT for feeling in the gaps :)
@atlantic_love
@atlantic_love 2 жыл бұрын
I see what you did there lol. Get back to programming :D
@YoshBruh
@YoshBruh 4 жыл бұрын
The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make a donation or view additional materials from hundreds of MIT courses, visit MIT OpenCourseWare at ocw.mit.edu
@leokettner636
@leokettner636 7 жыл бұрын
The title of this lecture should be "funception"
@ziadanwar5296
@ziadanwar5296 3 жыл бұрын
I came down searching for that comment Lmao
@aymensekhri2133
@aymensekhri2133 5 жыл бұрын
Thanks a lot Dr. Ana Bell
@MrFaiqueShakil
@MrFaiqueShakil 4 жыл бұрын
What's the shortcut for deleting the hash # from each line at once, like Professor Ana bell does regularly in Spyder IDE.
@maheraberu2000
@maheraberu2000 3 жыл бұрын
strg+1
@Liaomiao
@Liaomiao 7 жыл бұрын
why did it print with return and without return twice?
@LauBoonhai
@LauBoonhai 3 ай бұрын
Yes, why?
@pianoworld_1
@pianoworld_1 Жыл бұрын
What a coincidence , it's also raining In my city Hyderabad Pakistan due to a cyclone.
@yuminkim7264
@yuminkim7264 7 жыл бұрын
a nice lecture. Thanks!
@MrFaiqueShakil
@MrFaiqueShakil 4 жыл бұрын
best function lecture ever.
@danielrio1967
@danielrio1967 6 жыл бұрын
Nice! i will come to US in few years!
@x15cyberrush9
@x15cyberrush9 5 жыл бұрын
@@mzaje9803 who r you to say that? don't underestimate india ns and Chinese
@theDrake-tx1vj
@theDrake-tx1vj 7 жыл бұрын
if suppose the function h() in the last example is called twice, does the "scope" remain or is it formed twice? pls help
@rootytuners
@rootytuners 4 жыл бұрын
It is a fresh scope on each call.
@edogg5690
@edogg5690 6 жыл бұрын
Can anyone ELI5 what it means to provide abstraction? She says that writing the docstring provides abstraction and I'm just not familiar with that meaning.
@saurabh75prakash
@saurabh75prakash 6 жыл бұрын
E Dogg , Abstraction means that you need not look into the details of the function to use it( remember the projector example). The docstring provides the high level idea about the function which can help you in reusing the function in your code (without looking into the details of function's code)
@tcchan14
@tcchan14 7 жыл бұрын
Which lecture is required to do pset2?
@andreymlv
@andreymlv 4 жыл бұрын
ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/syllabus/
@LXMP284
@LXMP284 Жыл бұрын
Is it just me or is the scope structure in python eerily reminiscent of the way tangent universes are described in Donnie Darko (director’s cut)? 🤔🤔 just a thought!
@EgeOnatDoguslu
@EgeOnatDoguslu 6 жыл бұрын
Assignment: Hangman github.com/egeonatdoguslu/MIT-Assignments/blob/Hangman/Hangman
@pricesmith8450
@pricesmith8450 6 жыл бұрын
got any of the other assignments? would love to compare some of mine
@pricesmith8450
@pricesmith8450 6 жыл бұрын
Is it bad style to use a variable from outside the scope of a function?
@pricesmith8450
@pricesmith8450 6 жыл бұрын
nvm.. yes.
@ayandamarotya9607
@ayandamarotya9607 6 жыл бұрын
depends on the assignment preference of that variable you will be using... only assign global variables when you will access them from more than one function...
@Liaomiao
@Liaomiao 7 жыл бұрын
when you print(function_name) it just prints out what the function returns?
@leboyoyo
@leboyoyo 6 жыл бұрын
Liaomiao yes
@rootytuners
@rootytuners 4 жыл бұрын
@Liaomiao - actually no. print(function_name) will print the function object in memory; something like: . print(function_name()) with the parentheses will print what the function returns.
@kattetivikram1862
@kattetivikram1862 6 жыл бұрын
Iam mca student in india.it has very useful to me
@lc0414
@lc0414 4 жыл бұрын
real lecture starts at 11:00
@HadeelHanaysheh
@HadeelHanaysheh 7 жыл бұрын
why we are didn't use x ='abc' on any where ???
@andredc161
@andredc161 7 жыл бұрын
because it never was used has a print(x) inside the function h(), and doesn´t has a return. So it returns None
@McAwesomeReaper
@McAwesomeReaper Жыл бұрын
She wears the same outfit for every lecture. Just an observation, not a criticism. It's a nice outfit that strikes the perfect balance, I can see why she settled on this look in particular.
@doraemongameplay5683
@doraemongameplay5683 4 жыл бұрын
im 12 and i dont understand what is func, help...
@miscellany9674
@miscellany9674 Жыл бұрын
تحياتي للعميد بامطرف
@Linux4Ever2011
@Linux4Ever2011 5 жыл бұрын
Thank you for such clear explanation :)
@emansalah2766
@emansalah2766 6 жыл бұрын
Where do I get the python tutor ?
@estherweyinmikoloh7182
@estherweyinmikoloh7182 6 жыл бұрын
pythontutor.com
@saurabhmiyani9014
@saurabhmiyani9014 4 жыл бұрын
Thanks MIT
@denniskamonde6836
@denniskamonde6836 7 жыл бұрын
great job
@jongcheulkim7284
@jongcheulkim7284 2 жыл бұрын
Thank you.
@jadenmax679
@jadenmax679 5 жыл бұрын
Great. Thank you.
@samratdalal6878
@samratdalal6878 4 жыл бұрын
It's awesome.
@riccardovasellini6570
@riccardovasellini6570 5 жыл бұрын
Does anyone know how she deletes all the # character at once?
@DaljitSingh-ei9re
@DaljitSingh-ei9re 5 жыл бұрын
'Ctrl' + '/'
@GhostkillerPlaysMC
@GhostkillerPlaysMC 5 жыл бұрын
Lol even at MIT the students begin packing up before the professor is done teaching
@woddlyoats
@woddlyoats Жыл бұрын
It's sad
@dmac4u2luv
@dmac4u2luv 5 жыл бұрын
Brilliant!
@nazeehsaifi916
@nazeehsaifi916 7 жыл бұрын
Thank you
@quocvu9847
@quocvu9847 Жыл бұрын
34:34
@tanphanvan2693
@tanphanvan2693 3 жыл бұрын
Great lecture. Anyone has the solution for the assignment? Thanks very much!
@zigginzag584
@zigginzag584 4 жыл бұрын
Hello class!
@dani7599
@dani7599 6 жыл бұрын
I love the fact that American students are pretty confident to claim that they can make projectors using given components after the professor asked about it. In my country and in UK, nobody wants to look smart even though they are able to do the same.
@alexandrugheorghe5610
@alexandrugheorghe5610 Жыл бұрын
29:03 "so z is func_c" should have been "so z is func_a"
@shubhankarsingh4065
@shubhankarsingh4065 3 жыл бұрын
19:23 when you hit a function call
@aftabahmed2460
@aftabahmed2460 6 жыл бұрын
informative
@tawfeeqmuallem9086
@tawfeeqmuallem9086 6 жыл бұрын
I LLLLOOOOVVVEEE YOUUUUUUUUUUUU
@kunjs3687
@kunjs3687 4 жыл бұрын
IM 11 AND MY DAD IS EXPECTING ME TO UNDERSTAND THESE VIDEOS. I CAN'T UNDERSTAND ONE BIT< SO MY DAD IS GETTING REALLY MAD AT ME. CAN U PLEASE MAKE SOME VIDEOS THAT I MAY UNDERSTAND
@mitocw
@mitocw 4 жыл бұрын
We recommend you try the materials through the Edx course. It just started today! It has a place to get help and ask questions. www.edx.org/course/introduction-to-computer-science-and-programming-7. Also, if this course is still confusing try another resource/course. There are many available. Another view can help. Also, if English is not your native language, try a course that is in your language. Best wishes on your studies!
@woddlyoats
@woddlyoats Жыл бұрын
If your dad is getting mad then he is a really pathetic person.
@hamids4550
@hamids4550 7 жыл бұрын
I was okay until you got to the last example. Totally lost you :P I'll keep watching it until i get it. Thanks for posting
@sridharr8306
@sridharr8306 7 жыл бұрын
Try to do that bit by yourself, using python tutor. It will be clear
@devzoi3715
@devzoi3715 6 жыл бұрын
i didnt use it my mom did
@joaooliveira185
@joaooliveira185 Жыл бұрын
Based
@ashen1970
@ashen1970 5 жыл бұрын
Whoever edited this open courses must didn’t want to leak the major part of MIT’s succeed in education.
@simarmalhan6527
@simarmalhan6527 2 жыл бұрын
Pam beesly
@LordAhmedAmr
@LordAhmedAmr 7 жыл бұрын
any one here solved the 'hangman' assignment
@EgeOnatDoguslu
@EgeOnatDoguslu 6 жыл бұрын
github.com/egeonatdoguslu/MIT-Assignments/blob/Hangman/Hangman
@bobanmilisavljevic7857
@bobanmilisavljevic7857 11 ай бұрын
🦾🤠🇺🇲
@daveyjones9699
@daveyjones9699 5 жыл бұрын
These cameramen really suck at focusing on the slides. I don't need to see her face while she's explaining the slides. These videos are hard to watch and take notes on 2x speed.
@yukeyang5735
@yukeyang5735 6 жыл бұрын
Why is the teacher always in the same outfit?Curious.
@woddlyoats
@woddlyoats Жыл бұрын
It's her look
@avinashdwivedi2015
@avinashdwivedi2015 5 жыл бұрын
Clickbait
Function Calls
2:35
MIT OpenCourseWare
Рет қаралды 60 М.
8. Object Oriented Programming
41:44
MIT OpenCourseWare
Рет қаралды 632 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
5. Tuples, Lists, Aliasing, Mutability, and Cloning
41:28
MIT OpenCourseWare
Рет қаралды 231 М.
10. Understanding Program Efficiency, Part 1
51:26
MIT OpenCourseWare
Рет қаралды 238 М.
4. Assembly Language & Computer Architecture
1:17:35
MIT OpenCourseWare
Рет қаралды 732 М.
Lec 4 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008
51:27
6. Recursion and Dictionaries
48:22
MIT OpenCourseWare
Рет қаралды 380 М.
Lecture 1A: Overview and Introduction to Lisp
1:12:56
MIT OpenCourseWare
Рет қаралды 280 М.
9. Python Classes and Inheritance
47:28
MIT OpenCourseWare
Рет қаралды 208 М.
Lecture 1: Introduction to CS and Programming Using Python
1:03:30
MIT OpenCourseWare
Рет қаралды 915 М.
6. Multicore Programming
1:16:46
MIT OpenCourseWare
Рет қаралды 141 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН