Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'diff =' vs 'diff :=' #16

Open
vzhgit opened this issue Nov 11, 2024 · 1 comment
Open

'diff =' vs 'diff :=' #16

vzhgit opened this issue Nov 11, 2024 · 1 comment

Comments

@vzhgit
Copy link

vzhgit commented Nov 11, 2024

Hello.
I'm reading a traslated version of the book so I can't say on which page is following example but it contains two errors:

>>> tweet_limit = 280
>>> tweet_string = "Blah" * 50
>>> if diff := tweet_limit - len(tweet_string) >= 0;
...     print("A fitting tweet")
... else:
...     print("Went over by", abs(diff))
...
A fitting tweet

First error is invalid syntax: ';'
Second error about logic: in your exanple diff variable has boolean type so print("Went over by", abs(diff)) will always print 0 instead of number of characters.
The correct version of condition:

if (diff := tweet_limit - len(tweet_string)) >= 0:

https://stackoverflow.com/a/63876683/6188044

@madscheme
Copy link
Owner

That looks like an error in translation. The printed and online versions contain a colon, not a semicolon.

Thanks for pointing this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants