Learn Enough Python to be Useful Part 2 - Online Free Computer Tutorials.

'Software Development, Games Development, Mobile Development, iOS Development, Android Development, Window Phone Development. Dot Net, Window Services,WCF Services, Web Services, MVC, MySQL, SQL Server and Oracle Tutorials, Articles and their Resources

Sunday, April 14, 2019

Learn Enough Python to be Useful Part 2

How to Use if __name__ == "__main__ "This article is one in a series to help you become comfortable in Python scripting land. It's for data scientists and anyone new to Python programming.cat_breed = maine_coonif __name__ == "__main__": is one of those things you see in Python scripts that often isn't explained. You might have seen a hundred tutorials on Python list comprehensions, but Python scripting conventions get short shrift. In this article I'll help you connect the dots.state = maineif __name__ == "__main__": ensures that the code in the if block runs only when the file in which it is found is run directly. Let's break down how this works.What is it?Every Python file gets a special attribute called __name__ .Test it. Create a Python file my_script.py with print(__name__) as the only content. Then run python my_script.py in your terminal. __main__ is what you'll see.Note, those are double underlines on both sides of name. Those are called dunders for double underscores. They are also know as magic methods or special methods.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to


software-development,programming,towards-data-science,data-science,python

No comments:

Post a Comment