What is the difference between 'function(variable)' and 'variable.function()'

https://www.codecademy.com/courses/learn-python-3/lessons/use-python-list/exercises/sort?action=resume_content_item

In the case of the exercise addresses.sort() works rather than sort(addresses)

Whereas, print(addresses) works as such, and addresses.print() does not.

Thanks

print() is a standard function that belongs to no one class. Any class of object can be given as the argument and the print function will do its best to output it to the display.

.sort() is a method of the list class, and can only be called on a list object.

There is a standard function form of sort, known as sorted() that can be applied to more than one class of object except things like numbers and strings.

For now, set the question aside just long enough to reach the unit(s) on lists and dictionaries and touch on the units on OOP.

Thank you! I had the feeling they were skipping over some vital info. Glad to hear all should become clearer further as I progress through the course.

1 Like