給定多個 int 類型,任務是編寫一個 Python 程序將其轉換為 index 。
例子:
Input: 19 Output: 1.900000e+01 Input: 2002 Output: 2.002000e+03 Input: 110102 Output: 1.101020e+05
方法:
- 我們將首先聲明並初始化一個整數
- 然後我們將使用格式方法將數字從整數轉換為 index 類型。
- 然後我們將打印轉換後的值。
用法:
String {field_name:conversion} Example.format(value)
錯誤和異常:
ValueError:Error occurs during type conversion in this method.
更多參數可以包含在我們語法的花括號中。使用格式碼語法{field_name:conversion},其中field_name指定str.format()方法的參數的索引號,conversion指的是數據類型的轉換碼。
例:
Python3
# Python program to convert int to exponential
# Declaring the integer number
int_number = 110102
# Converting the integer number to exponential number
exp_number = "{:e}".format(int_number)
# Printing the converted number
print("Integer Number:",int_number)
print("Exponent Number:",exp_number)
輸出:
Integer Number:110102 Exponent Number:1.101020e+05
相關用法
- Python exponential轉float用法及代碼示例
- Python float轉exponential用法及代碼示例
- Python sympy.stats.Exponential()用法及代碼示例
- Python numpy.random.exponential()用法及代碼示例
- Java long轉int用法及代碼示例
- Java int轉long用法及代碼示例
- Python Bytes轉Int用法及代碼示例
- Python Float轉Int用法及代碼示例
- Python Int轉Bytes用法及代碼示例
- Python int()用法及代碼示例
注:本文由純淨天空篩選整理自aditya_taparia大神的英文原創作品 Python program to convert int to exponential。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。