Fixing grammar in Python?
Go to solution
Solved by Guest,
21 hours ago, Red Saum said:EDIT: I think I figured it out, but is there a more efficient way to do this certain thing than:
def lumberjack(name, pronoun): if name[-1] == 's': print("{}' a lumberjack and {} OK!".format(name, pronoun)) else: print("{}'s a lumberjack and {} OK!".format(name, pronoun)) lumberjack("Ashton", "he's") lumberjack("Paris", "he's") lumberjack("Sam", "they're")
One way you could make it a little more efficient is to use f-strings instead of .format(). An example:
def lumberjack(name, pronoun): if name[-1] == 's': print(f"{name}' a lumberjack and {pronoun} OK!") else: print(f"{name}'s a lumberjack and {pronoun} OK!") lumberjack("Ashton", "he's") lumberjack("Paris", "he's") lumberjack("Sam", "they're")
Keep in mind this is a Python 3.6+ feature (A link for more comparisons) and there are some places where .format() is more appropriate.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now