简体   繁体   English

整数后的点在python中意味着什么?

[英]What does a dot after an integer mean in python?

I am looking at this line of python code (which seems to run properly): 我正在看这行python代码(似乎正常运行):

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

What is the dot doing after the 35? 35之后的点是做什么的? what does it do? 它有什么作用? Is it a signal to python that 35 is a float and not an integer? 是否向python发出信号,表明35是浮点数而不是整数? I have not seen this before. 我以前没看过 Thanks! 谢谢!

This is easy to test, and you're right. 这很容易测试,而且您是对的。 The dot signals a float. 点表示浮动。

$ python
>>> 1.
1.0
>>> type(1.)
<type 'float'>

Float 浮动

Next time, try to explore this using Python 下次,尝试使用Python进行探索

r= 34.

print type(r)

Output: <type 'float'> 输出: <type 'float'>

It tells python to treat 3 as a float() . 它告诉python将3视为float() Its just a convenient way to make a number a float for division purposes then having to explicitly call float() on it. 这是将数字设为浮点数以便进行除法然后必须在其上显式调用float()一种简便方法。

For example: 例如:

my_float = 3.

typed_float = float(3)

my_float == typed_float
#=> True

type(my_float)
#=> <type 'float'>

In this case you need to typecast to a float to avoid the pitfalls of integer division. 在这种情况下,您需要强制转换为浮点数以避免整数除法的陷阱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM