What does a dot after an integer mean in python?

前端 未结 3 927
灰色年华
灰色年华 2020-12-07 00:45

I am looking at this line of python code (which seems to run properly):

import numpy as np
yl = 300 + 63*np.exp(-x/35.)

What is the dot doi

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 00:57

    It tells python to treat 3 as a float(). Its just a convenient way to make a number a float for division purposes then having to explicitly call float() on it.

    For example:

    my_float = 3.
    
    typed_float = float(3)
    
    my_float == typed_float
    #=> True
    
    type(my_float)
    #=> 
    

    In this case you need to typecast to a float to avoid the pitfalls of integer division.

提交回复
热议问题