Pythonで数値計算を行っていると、整数(int)と浮動小数点数(float)を行き来させたい場面が頻繁にあります。 「平均点を計算するために、整数の合計点を小数に変換したい」 「計算結果の小数を、個数として扱いたいので整数に戻したい」 Pythonには ...
print(int(5.5)) #to convert to int : output should be 5 print(float(5)) #to convert to float : output should be 5.0 ...
"""Explicit type conversion is the conversion of one data type to another by the user. This is called explicit type conversion. It is done by the user to avoid data loss.""" # For example, when you ...
a = 10 b = 3 result = a * b print(result) # 30 べき乗 (**) result = 2 ** 3 # 2の3乗 print(result) # 8 result = 5 ** 2 # 5の2乗 print(result) # 25 摂氏30度 ...