The biggest difference between Python2 and Python3 division:
Python2:
Print 500/1000
Python2 Result: take integer part, decimal is not preserved
0Process finished with exit code 0
Python3:
Print 500/1000
Python3 results: get real results, decimal retention
0.5Process finished with exit code 0
So, what do you do if python2 want to keep the fractional part?
You only need to add an import package. It's all right. No other action required
from __future__ Import # when used/divided, the real result is preserved. Decimal
After adding the import package, the Python2 operation:
# Coding:utf-8 from __future__ Import Division Print 500/1000
Results:
0.5Process finished with exit code 0
There is another way. Convert the divisor or the divisor by two or at least one of the other to float type:
Print Float (500)/1000
Results:
0.5Process finished with exit code 0
Gmt
|
Detect languageAfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutch中文版EsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu |
|
AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutch中文版EsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu |
|
|
|
|
|
Text-to-Speech function is limited to characters
|
|
Options:History:Feedback:Donate |
Close |
Python2 Division preserves Real Results