I don't understand why programmers use %s, when they can simply just add the variable name to the print statement. I mean its less work to type in the variable name instead of " ...%s" % name) "
Example:
# declaring a string variable
name = "David"
# append a string within a string
print("Hey, %s!" % name)`
Why do Programmers not type in instead:
# declaring a string variable
name = "David"
# printing a salutation without having to append a string within a string:
print("Hey," + " " + name + "!")`
```
%
-formatted version easier to read in this case, and that counts for a lot. But I find the f-string version even easier to read (print(f"Hey, {name}!")
), and that's generally what I would use in cases like this.