-
-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
Hi. The idea arose to make the common part of the string a constant. That is, if part of the string is repeated in the code, then you should put it into a constant and then insert it using string formatting. I also want to note that it is worth doing this optionally because it affects performance and RAM consumption. For example:
def test(name):
return f"Hello, {name}!"
name = input("Enter your name: ")
if name != "":
print(test(name))
else:
print("Please enter your name")it can be reduced to the form:
A='nter your name: '
def test(name):
return f"Hello, {name}!"
name = input("E%s"%A)
if name != "":
print(test(name))
else:
print("Please e%s"%A)In this example, the difference is only 1 byte. And this example is needed solely to show how I see it. In other cases, the difference in occupied space may be greater.
The example is taken from one of the issues
Metadata
Metadata
Assignees
Labels
No labels