Search code examples
pythonstringformat-string

how shall i call out this function using string format method?


i'm learning Python and have began with Google's Python Automation Beginner course. Idk if i chose it right but im already in week 4 and now have started facing confusion.

Fill in the gaps in the nametag function so that it uses the format method to return first_name and the first initial of last_name followed by a period. For example, nametag("Jane", "Smith") should return "Jane S."

  def nametag(first_name, last_name):
return("___.".format(___))

Solution

  • def nametag(first_name, last_name):
        return '{} {}.'.format(first_name, last_name[0])
    

    will put the arguments of format in place of the brackets.