hairinmybellybutt@lemmy.world to Programmer Humor@lemmy.mlEnglish · 11 months agowould you write web app with this?lemmy.worldimagemessage-square54fedilinkarrow-up1288arrow-down132
arrow-up1256arrow-down1imagewould you write web app with this?lemmy.worldhairinmybellybutt@lemmy.world to Programmer Humor@lemmy.mlEnglish · 11 months agomessage-square54fedilink
minus-squaretryptaminev 🇵🇸 🇺🇦 🇪🇺@feddit.delinkfedilinkarrow-up9·11 months agoexample: i = 5.0//2 list[i] throws an error because i is double and the list-index expects an integer. so for it to work the code needs to look like this: i = int(5.0//2) list[i] meanwhile this works: i=5 i= ‘abcde’
minus-squareGebruikersnaam@lemmy.mllinkfedilinkarrow-up3·11 months agoIt is but if you start with a float you get a float back.
minus-squareChrobin@discuss.tchncs.delinkfedilinkarrow-up2·11 months agoYou’re right, I did not know that. Thanks!
minus-squareGebruikersnaam@lemmy.mllinkfedilinkarrow-up1·11 months agoWas really surprised by this too, because iirc Python 2 did not do this.
minus-squaredzervas@lemmy.worldlinkfedilinkarrow-up1·11 months agoyou can do i: int to make this error out
minus-squareGebruikersnaam@lemmy.mllinkfedilinkarrow-up6·11 months agoNo, type hints are not enforced.
example:
throws an error because i is double and the list-index expects an integer.
so for it to work the code needs to look like this:
meanwhile this works:
Isn’t
//
integer division?It is but if you start with a float you get a float back.
You’re right, I did not know that. Thanks!
Was really surprised by this too, because iirc Python 2 did not do this.
you can do
i: int
to make this error outNo, type hints are not enforced.
damn