Fstrings
ASnake Documentation
Summary:
Python's f-string allows code expressions inside a string, making it easier to display things such as variables in a more understandable way.
Syntax f-string f"{}"
:
An f-string is a regular string, but with an f
before the first quotation mark. Any usual contents within a string can appear besides brackets, as that is used to signal when a internal code block is active. Once inside the code block, almost any Python/ASnake expression is allowed so long as it does not start it's own code block; such as non-ternary conditionals, or function defines.
f-strings have all sorts of crazy tricks and features which you can read about elsewhere to format the string the way you wish, in a concise manner.
Basic examples of it's usage:
name = "bob"
f"hi my name is {name}!"
# result: hi my name is bob!
f'wait is 12 greater than 5? is it {12>5}???'
# result wait is 12 greater than 5? is it True???
Multiple lines in fstring f'{x ; y}'
:
ASnake adds a feature to Python's f-strings. They have the ability to contain multiple lines, and even newlines. You need indentation which indicates the end of an expression, specifically these aliases:
- ;
- then
- do
When placed, it will create a new f-string expression next to the prior.
Example:
f"{1 ; 2 ; 3}"
# result: 123
e = 'E'
f"dont make me angry or i will {82 to chr then e*20}!!!"
# result: dont make me angry or i will REEEEEEEEEEEEEEEEEEEE!!!
ASnake doesn't tend to care about indentation or newlines inside of f-strings, you can go pretty crazy:
f'my favorite number is {
12
}.'
# result: my favorite number is 12.