A mistake that can come up when programming is calling functions before defining them. In this video, learn how to avoid this mistake by defining functions before calling them in your code.
- [Instructor] A mistake that can come up when programming, … is calling functions before defining them. … For example, … say I have a variable named hospital lock … that contains the location of a hospital as a tuple, … a variable named school lock … that contains location of the school as a tuple, … and a variable named fire dept lock … that contains the location of a fire department as a tuple, … as shown here. … Now say I want to compute the Euclidean distances … between each pair of locations. … Since I have to use … the Euclidean distance formula each time, … I can write a function that applies … the Euclidean distance formula on a given pair of locations, … and use that function as needed. … Say I define a function named … Euclidean dist below like this. … Now let's say I call the Euclidean dist function … and pass in the appropriate locations up here. … Now I'll go ahead and run this up. … As you can see, when I ran this cell, … I got a name error that says, … name Euclidean dist not defined. …
Skill Level Intermediate
1. Avoid Mistakes in Coding Practices
2. Avoid Mistakes in Structuring Code
3. Avoid Mistakes in Handling Data
4. Avoid Mistakes in Machine Learning
Using redundant features1m 45s
Get started with Python1m 7s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.