bernie2436
bernie2436

Reputation: 23921

What does a dot after an integer mean in python?

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 doing after the 35? what does it do? Is it a signal to python that 35 is a float and not an integer? I have not seen this before. Thanks!

Upvotes: 30

Views: 27558

Answers (3)

Tim Zimmermann
Tim Zimmermann

Reputation: 6420

This is easy to test, and you're right. The dot signals a float.

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

Upvotes: 44

agconti
agconti

Reputation: 18123

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)
#=> <type 'float'>

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

Upvotes: 0

user3378649
user3378649

Reputation: 5354

Float

Next time, try to explore this using Python

r= 34.

print type(r)

Output: <type 'float'>

Upvotes: 8

Related Questions