Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
Use .format() to create a sentence: 'I like' + favorite_fruit
Remember to use {} as a placeholder for favorite_fruit.
What will this print: print('The answer is {}.'.format(42))?
Identify what .format() is replacing inside the string.
What does the .format() method do?
Think about how values are injected into a string.
True or False: The .format() method can only take one argument.
Recall examples with multiple variables.
Write a function that takes a name and age, and returns a string formatted as 'Name: {name}, Age: {age}'. Use .format() for formatting.
Think about how to plug the parameters into the string.
Given a list of scores, write code that outputs 'The scores are: score1, score2, score3' using .format() and unpack the list.
Remember how to unpack a list in .format()!
6 more questions in this section. Enroll free to practise them all.
Enroll free