From the course: Python Data Science Mistakes to Avoid

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Calling functions before defining

Calling functions before defining - Python Tutorial

From the course: Python Data Science Mistakes to Avoid

Start my 1-month free trial

Calling functions before defining

- [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…

Contents