整数と浮動小数点の除算
Python には 2 種類の除算演算子 / と // があります。Python 3 では、/ は常に浮動小数点の結果を返し、// は切り捨て除算で、常に整数の結果を返します。切り捨て除算は math.floor(numerator/divisor) と同じで、除算結果以下で最大の整数を返します。math.floor については Python Docs で詳しく学べます。
この演習はコースの一部です
Python のデータ型
演習の手順
2/1と1/2の結果を出力してください。2//1と1//2の切り捨て除算の結果を出力してください。2/1と2//1の型を出力してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Print the result of 2/1 and 1/2
print(____)
print(____)
# Print the floored division result of 2//1 and 1//2
print(____)
print(____)
# Print the type of 2/1 and 2//1
print(____)
print(____)