Capitalize First Letter In Words

PythonPythonBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In Python, we can capitalize the first letter of every word in a string using a built-in function. In this challenge, you will be asked to write a function that takes a string as an argument and returns a new string with the first letter of every word capitalized.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"]) python/BasicConceptsGroup -.-> python/comments("`Comments`") python/FunctionsGroup -.-> python/function_definition("`Function Definition`") subgraph Lab Skills python/comments -.-> lab-13595{{"`Capitalize First Letter In Words`"}} python/function_definition -.-> lab-13595{{"`Capitalize First Letter In Words`"}} end

Capitalize Every Word

Write a function capitalize_every_word(s) that takes a string s as an argument and returns a new string with the first letter of every word capitalized.

def capitalize_every_word(s):
  return s.title()
capitalize_every_word('hello world!') ## 'Hello World!'

Summary

In this challenge, you have learned how to capitalize the first letter of every word in a string using a built-in function in Python. This skill can be useful in various applications, such as formatting text for display or processing user input.

Other Python Tutorials you may like