Two Ways to Format Strings in Python

Python

Two ways to format strings with Python using the format method.

 1|  #1
 2|  teams = 'Home Team: {}, Away Team: {}'
 3|  teams.format('Man Utd','Arsenal')
 4|  
 5|  #2
 6|  teams = 'Home Team: {home_team}, Away Team: {away_team}'
 7|  teams.format(home_team='Man Utd', away_team='Arsenal')
Did you find this snippet useful?

Sign up for free to to add this to your code library