You are viewing a single thread.
View all comments View context

example:

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โ€™

permalink
report
parent
reply
2 points

Isnโ€™t // integer division?

permalink
report
parent
reply
3 points

It is but if you start with a float you get a float back.

permalink
report
parent
reply
2 points

Youโ€™re right, I did not know that. Thanks!

permalink
report
parent
reply
1 point

you can do i: int to make this error out

permalink
report
parent
reply
6 points

No, type hints are not enforced.

permalink
report
parent
reply
1 point

damn

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 6.8K

    Monthly active users

  • 1.4K

    Posts

  • 32K

    Comments