Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
% is one of the oldest Python syntaxes for interpolating strings. It basically works like: template_string % data_tuple In fact, you can literally do that: >>> s = "%d %d" >>&g...
Answer
#1: Initial revision
`%` is one of the oldest Python syntaxes for interpolating strings. It basically works like: ``` template_string % data_tuple ``` In fact, you can literally do that: ``` >>> s = "%d %d" >>> t = (1, 2) >>> s % t '1 2' ``` `template_string` is the template, `data_tuple` is the values to be used for rendering the template. Obviously they must match in number - if you have too few values in your tuple you'll get an error. These days, there are much better ways to do the same thing and I would recommend avoiding `%`: * `"A {} can live up to {} years".format(animal, age)"` - looks like a plain old function call, like `"HeLLo".lower()`. * `f"A {animal} can live up to {age}"` ("f-string") - syntactic sugar to make the above call to `.format` easier.