Use of . in python? -
this question has answer here:
- understanding dot notation in python 2 answers
i struggling explain use of dot. thought might way of multiplying variables error when try run such code.
i can't explain doing exactly, take code example:
import random in range(100): value = random.randint(1, 10) print(value)
i understand code in line 3 confused random.randint
dot doing here? randint
not defined or imported how program know being asked of it?
an brief explanation of above code nice explanation of use of dot in python appreciated.
you use dot 3 main reasons:
accessing members of module: module python file, , members can variables, functions, classes , on.
accessing modules within package: package directory containing a__init__ module. packages nested , contain inner packages. have reach innermost , module. both use dot syntax.
and @ last, accessing members of class, example method (functions) fields (variables) , on.
in above code random python module , accessing function randint.
Comments
Post a Comment