So I am new to Julia and learned various ways of string formatting. Mainly from websites similar to this.
So I use f-strings a lot in Python, not a big fan of .format(). So I was wondering since someone created Formatting.jl Package to bring .format() like feature in Julia, is there any ongoing or useful package which does same for f-strings? Now I googled a bit about it too but didn't find anything.
What my main issue is that I want to replicate this behaviour:
a = 10
b = 20
print(f'The multiplication is = {a * b}')
In case anyone wondering what are f-strings, refer to this.
Yes, it is possible with standard Julia strings:
x = "World!"
y = 42
greeting = "Hello $x, $(y^2) !" # gives "Hello World!, 1764 !"
See also here:
https://docs.julialang.org/en/v1/manual/strings/#string-interpolation
Edit: The example in the comment above is
j = 10; b = 20
println("The numbers and their square are $j, $b and $(j^2), $(b^2)")
If you want more control over numeric formatting than the default string interpolation, you can use the Formatting.jl package in Julia, which provides Python f-string functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With