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
Yep that’s unreadable
BaalKazar 14 points · Jan 2023
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
xaomaw 7 points · Jan 2023
What about
:⚪<10What does the
:do? How can you compare ⚪ to10?Arny597 5 points · Jan 2023
That’s the “fill result until 10 symbols long” part
xaomaw 1 points · Jan 2023
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
So I still have the question how can you compare
⚪ < 10? I would understand if ⚪ was defined as a variable containing thecount_of_white_dotsbefore, but it is NOT.Arny597 4 points · Jan 2023
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”
Synedh 2 points · Jan 2023 · :bash::py::ts:
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.xaomaw 2 points · Jan 2023
Thanks for clarification, I'll take a look into it!
Edit:
Now I understand it. Very cool
Synedh 2 points · Jan 2023 · :bash::py::ts:
Indeed, very useful for unit or date format, if you need your time on two chars, a simple
f"{hour:0<2}:{min:0<2}".Swoop3dp 2 points · Jan 2023
Basically left-pad but without the drama.
00PT 1 points · Jan 2023 · :j::js::py:
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.
BaalKazar 1 points · Jan 2023
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