It also hampers the readability of our code. This can lead to duplicate definitions for an identifier. Importing everything with the asterisk (*) symbol is not a good programming practice. This includes all names visible in our scope except those beginning with an underscore(private definitions). Here, we have imported all the definitions from the math module. ![]() In Python, we can import all names(definitions) from a module using the following construct: # import all names from the standard module math Here, we imported only the pi attribute from the math module. For example, # import only pi from math module We can import specific names from a module without importing the module as a whole. Hence, math.pi is invalid, and m.pi is the correct implementation. Note that the name math is not recognized in our scope. This can save us typing time in some cases. Here, We have renamed the math module as m. For example, # import module by renaming it In Python, we can also import a module by renaming it. For example, # import standard math module Suppose we want to get the value of pi, first we import the math module and use math.pi. We can import a module according to our needs. The Python standard library contains well over 200 modules.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |