-
Notifications
You must be signed in to change notification settings - Fork 450
Open
Description
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:
Metadata
Metadata
Assignees
Labels
No labels