Practice Printing with .format() - 18.10 | 18. PRINT | CBSE Class 9 AI (Artificial Intelligence)
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

Practice Questions

Test your understanding with targeted questions related to the topic.

Question 1

Easy

Use .format() to create a sentence: 'I like' + favorite_fruit

💡 Hint: Remember to use {} as a placeholder for favorite_fruit.

Question 2

Easy

What will this print: print('The answer is {}.'.format(42))?

💡 Hint: Identify what .format() is replacing inside the string.

Practice 4 more questions and get performance evaluation

Interactive Quizzes

Engage in quick quizzes to reinforce what you've learned and check your comprehension.

Question 1

What does the .format() method do?

  • Joins strings directly
  • Replaces placeholders with values
  • Adds numbers together

💡 Hint: Think about how values are injected into a string.

Question 2

True or False: The .format() method can only take one argument.

  • True
  • False

💡 Hint: Recall examples with multiple variables.

Solve 2 more questions and get performance evaluation

Challenge Problems

Push your limits with challenges.

Question 1

Write a function that takes a name and age, and returns a string formatted as 'Name: {name}, Age: {age}'. Use .format() for formatting.

💡 Hint: Think about how to plug the parameters into the string.

Question 2

Given a list of scores, write code that outputs 'The scores are: score1, score2, score3' using .format() and unpack the list.

💡 Hint: Remember how to unpack a list in .format()!

Challenge and get performance evaluation