Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialsunil shrestha
735 PointsLocal Variable accessible
since entry is an local variable how can delete_entry(entry) function is able to access entry?
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsGreat question! Python passes variables to functions using “pass by object reference”. So in the function view_entries, the calling code delete_entry(entry)
, refers to the variable entry as defined by the containing for
loop. A pointer to this object (its address) is passed to the function delete_entry. Any references to the variable “entry” within the called function point to the same object. Effectively, this makes “entry” non-local.
In other words, the objects passed to a function are not local to the function.
One caveat to this concept is if event
were to be assigned within the function delete_entry
, the variable event
would become local so the outer scoped object passed to the function would not be overwritten.
Post back if you need more help. Good luck!!!