[GO] Python> int ('1e3')> ValueError: invalid literal for int () with base 10: '1e3' / str (1e3)> '1000.0'

Operating environment


Xeon E5-2620 v4 (8 cores) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 and its-devel
mpich.x86_64 3.1-5.el6 and its-devel
gcc version 4.4.7 (And gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Use 1.

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic

int to string

It was written in the above book that when using int (), an error occurs in the description of the exponential format such as ʻint ('1e3') `(@ No.733 / 12833).

I've tried.

int_func_170120.py


ival1=int('1000')
print(ival1)
ival2=int('1e3')
print(ival2)

result


$ python int_func_170120.py 
1000
Traceback (most recent call last):
  File "int_func_170120.py", line 3, in <module>
    ival2=int('1e3')
ValueError: invalid literal for int() with base 10: '1e3'

string to int

What I was curious about when doing the above was what if the 1e3 was converted to str.

I've tried.

str_func_170120.py


str1=str(1000)
print(str1)
str2=str(1e3)
print(str2)

result


1000
1000.0

The number 1e3 seems to be a string type after being converted to 1000.0.

It was also mentioned in the above book (@ No. 831/12833).

Recommended Posts

Python> int ('1e3')> ValueError: invalid literal for int () with base 10: '1e3' / str (1e3)> '1000.0'
Handle Base91 keys with python + redis.
Python script for ldapsearch base64 decode
Getting Started with Python for PHPer-Classes
Getting Started with Python for PHPer-Functions
Easy keyword extraction with TermExtract for Python
INSERT into MySQL with Python [For beginners]
WEB scraping with Python (for personal notes)
Manually ssh registration for coreserver with python
Use DeepL with python (for dissertation translation)
Amplify images for machine learning with python
Tips for dealing with binaries in Python
[Python] Get the variable name with str
Tips for using python + caffe with TSUBAME
[Shakyo] Encounter with Python for machine learning
Process multiple lists with for in Python
[python, openCV] base64 Face recognition with images
Getting Started with Python for PHPer-Super Basics
Debug for mysql connection with python mysql.connector
[Python] Read images with OpenCV (for beginners)
WebApi creation with Python (CRUD creation) For beginners
Preparation for scraping with python [Chocolate flavor]
[For beginners] Try web scraping with Python