Master string formatting in Python using f-strings to join first and last names into a formatted full name.
Learn how to convert minutes into seconds in Python using arithmetic multiplication and basic unit conversions.
Create a function concat_name(first_name, last_name) that takes a first and last name and returns a single formatted string as "last_name, first_name".
Formatting display names cleanly is standard requirement across user profiles, invoice PDF generators, and email notifications.
Use Python f-strings (f"{last_name}, {first_name}"):
def concat_name(first_name, last_name):
return f"{last_name}, {first_name}"
# Testing our function
print(concat_name("First", "Last")) # Output: "Last, First"
print(concat_name("John", "Doe")) # Output: "Doe, John"
print(concat_name("Mary", "Jane")) # Output: "Jane, Mary"
Introduced in Python 3.6, f-strings (formatted string literals) are faster, cleaner, and less error-prone than legacy % formatting or " + " string concatenation.
"Last, First" order rather than "First Last".Use f-strings for all string formatting. Next, let's calculate factorials in Python!