Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I am trying to use 1e6 to return 1000000, but I need to set the '6' to a variable. But
1e6
units = int(6) 1e(units)
gives me a syntax error. The python reference docs have no details on how to use variables instead of ints to achieve this.
The e notation is just short for 10 raised to a power, so you can do something similar
e
>>> units = 6 >>> 10 ** units 1000000
Or more generally
def e(base, exp): return base * 10 ** exp >>> e(1, 6) # 1e6 1000000 >>> e(2.5, 6) # 2.5e6 2500000.0
Add a comment
You can do as CoryKramer suggested, heres other way below:
>>> units = 6 >>> float(f'1e{units}') 1000000.0
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.