Python f-strings > Dutch government
31 comments · 83% upvoted · source · other discussions
31 comments · 83% upvoted · source · other discussions
Yep that’s unreadable
percentage times ten, min(result, 10)
(x) times result
(0) fill until result gets 10 symbols long
Pretty readable imo, I don’t even know/do python
What about :⚪<10
What does the : do? How can you compare ⚪ to 10?
That’s the “fill result until 10 symbols long” part
Okay so I got the answer. The colon : itself stands for an if-statement. That's what my first question was about.
But even then the comparison is
if ⚪ < 10:
🔵 * count_of_blue_dots
So I still have the question how can you compare ⚪ < 10? I would understand if ⚪ was defined as a variable containing the count_of_white_dots before, but it is NOT.
How do you know it’s an if statement when colons have an entirely different function in python as well? This link tells you how colon operators are used for string slicing. So maybe it’s formatting the blue dot to be as many times as the percentage, then filling the string with white dots as long as the string is less than 10 elements long
EDIT: not only that, but when colons ARE used in an if statement, it’s never to replace the words. The ternary operators “?” And “:” which mean “if” and “else” respectively do not exist in python. Shorthand if statements always use the keywords still, such as “a if b else c”
It's not an if-statement, it's a format delimiter.
In python, you can format your in-string argument this way : f"Foo {val:format}" where format is a mini-language by itself. It is a very powerful and an efficient way to deal with strings formating.
It looks like one of those obscure syntax elements that is convenient, powerful, and makes sense, but not at all intuitively understood unless you are specifically told how it works or look it up. There seems to be many of these in Python. It's not good for widespread readability.
Honestly I actually don’t know what the syntax exactly did.
The curly braces with such a comparison made it look like a loop to me. Then I imagined Python doing Python things in which comparing the string against an integer somehow compares the length of the string.
I can imagine automatic refactoring coming up with stuff luck this, I don’t know how alien that syntax is to python bases though, but the case it self is quirky enough
I don't like how 10 is written there as a literal 3 times. It should be a function parameter that defaults to 10
My first thought was "Arjan Codes". A bit unfair to the guy, TBH.
Hard to read, performance is probably worse. But hey, it is 🐍. You cannot expect much from a language with disabilities.
language with disabilities
Do you mean the lack of multi-line lambdas?
Or that peculiarity with multable default function arguments?
----
These two things are pretty annoying, but everything else is completely fine in Python.
There are also various syntax quirks such as ternary expressions having the result be on the left and variable usages coming before the definitions in certain expressions. This makes it less intuitive for people who come from languages other than Python.
OK, ternary syntax is very unusual to me. The whole point of the ternary expression is to be readable while occupying only 1 line.
variable usages coming before the definitions in certain expressions
Could you elaborate please? It seems I missed this one.
This makes it less intuitive for people who come from languages other than Python
Maybe, my acquintance with Ruby made me think that Python is sufficiently reasonable.
In ruby 0 is True, and, AFAIK, there is a different operator precedence for AND and OR.
Percentage rounds, the favorite snack of a mathematician.
Is it pythonic enough?
Upbeat_Spite_9674 36 points · Jan 2023
sobov 13 points · Jan 2023
Yeah. Let's make it even more unreadable