3 ms·
Howdy Zed, there's a small typo in your printf statement. As written, x = 'Zed' print f"Howdy {x}" Should read, x = 'Zed' printf "Howdy {x}"
by justinator 10y ago
Howdy Zed, there's a small typo in your printf statement. As written,
x = 'Zed'
print f"Howdy {x}"
Should read,
x = 'Zed'
printf "Howdy {x}"
I was under the suspicion that, "f" was some sort of operator or something, much like q is for Perl,
print q{Howdy Zend};
- rryan 10y agoNo, it's correct (new in Python 3.6): https://www.python.org/dev/peps/pep-0498/ https://www.python.org/dev/peps/pep-0498/ The print statement however is not valid Python 3 :).
- deleted 10y ago[deleted]
- rat87 10y agonope it should be print(f"Howdy {x}") It's a new python 3.6 feature called f-strings/string interpolation https://docs.python.org/3.6/reference/lexical_analysis.html#f-strings https://docs.python.org/3.6/reference/lexical_analysis.html#... That said in python3 print is a function not a statement and requires parenthesis so he still has a typo.
- pmontra 10y agoI know f-strings but I still can't believe them. There are parts of Python that look like it wants programmers do low level compiler job and I can't understand why. This is one of them. Python can do %s string interpolation without some s'' s-strings so I wonder why it needs this f-string thing. Many languages can do string interpolation without having developers babysitting the interpreter. In 2016 we have the CPUs to make it happen the other way around.
- rat87 10y agoIt has to do with backwards compatibility in syntax if they had been smart enough to introduce in python3 they could have done it without the f.