5,321
edits
(→Tuples) |
|||
Line 255: | Line 255: | ||
===if main=== | ===if main=== | ||
[https://stackoverflow.com/questions/419163/what-does-if-name-main-do What does if __name__ == "__main__" do?] | |||
If you are writing a script with functions you want to be included in other scripts, use <code>__name__</code> to detect if your script is being run or being imported. | If you are writing a script with functions you want to be included in other scripts, use <code>__name__</code> to detect if your script is being run or being imported. | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
if __name__ == "__main__": | if __name__ == "__main__": | ||
# do..something..here | |||
</syntaxhighlight> | </syntaxhighlight> | ||
===iterators and iterables=== | ===iterators and iterables=== |