Monday, 20 July 2015

Python Underscore "_" in Method and Variable Names

Cited from Python: Why do some functions have underscores “__” before and after the function name?

One underline in the beginning:

"Python doesn't have real private methods, so one underline in the start of a method or attribute means you shouldn't access this method."

Two underlines in the beginning:

"So, when you create a method starting with __ it means that you don't want to anyone can override it, it will be accessible only from inside the own class."

Two underlines in the beginning and in the end:

"When we see a method like __this__, don't call it. Because it means it's a method which Python calls, not by you."


No comments:

Post a Comment