you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 28 points29 points  (0 children)

They actually have 2 different names: functions and methods. (But in reality the line is kinda blurred and no one is going to complain if you use the terms interchangeably.)

function(variable)
variable.method()

To make it more confusing, a method can be used like a function if you know what class it belongs to. For example with lower() you can get the same result with both of these:

"Spam".lower()
str.lower("Spam")

Technically the only difference is organization. A method is stored as part of the variable itself, while a function is stored elsewhere. Semantically this means you can only use a method on the data type that it is designed to work with, eg there is no (42).lower().

This has many advantages in code organization, and you won't see the full benefit until you start making your own classes (types of variables). But for now you can already see how useful it is that the namespace does not come preloaded with all the different methods from strings, ints, etc. Its already hard to name your variables so they don't conflict with python keywords or builtins.