「Python3.9」float型の数値を文字列にするサンプル

環境
Python 3.9.13
Windows 11 Pro 21H2 64bit
PyCharm 2022.2.1 (Community Edition)

構文
変数名 =値
type(変数名)
type関数でデータ型を確認しています

str(変数名)
str関数で文字列に変換しています。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
aa = 24.56
print(type(aa))
res = str(aa)
print(type(res))
print(res)
aa = 24.56 print(type(aa)) res = str(aa) print(type(res)) print(res)
aa = 24.56
print(type(aa))

res = str(aa)
print(type(res))
print(res)

実行結果
<class 'float’>
<class 'str’>
24.56

Python

Posted by arkgame