Use of . in python? -


this question has answer here:

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:

  1. accessing members of module: module python file, , members can variables, functions, classes , on.

  2. accessing modules within package: package directory containing a__init__ module. packages nested , contain inner packages. have reach innermost , module. both use dot syntax.

  3. and @ last, accessing members of class, example method (functions) fields (variables) , on.

in above code random python module , accessing function randint.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -