Remember
capitalize() returns a string with its first character titlecased and the remaining characters lowercased.
capitalize() returns a string with its first character titlecased and the remaining characters lowercased.
Follow the example, change its sample, and compare what happens.
Explain the result and test your understanding.
Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.
Follow the code and watch its state change. Guided simulation.
text = 'hELLO WORLD'
result = text.capitalize()
print(result)Top-level scope
'hELLO WORLD'Object 2 · str'Hello world'capitalize() returns a string with its first character titlecased and the remaining characters lowercased.
(no output)
What do you expect this program to print?
EXAMPLE INSTRUCTIONS
text = 'hELLO WORLD'
result = text.capitalize()
print(result)
|
v
DISPLAYED RESULT
Hello world
FINAL BINDINGS
text --> object 1 (str)
result --> object 2 (str)
object 1: 'hELLO WORLD'
object 2: 'Hello world'Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.
Choose a sample and follow its execution. Guided simulation.
text = 'hELLO WORLD'
result = text.capitalize()
print(result)Top-level scope
'hELLO WORLD'Object 2 · str'Hello world'The example has finished. Compare the final output with the values and references above.
Hello world
What do you expect this program to print?
text = 'hELLO WORLD'
result = text.capitalize()
print(result)String capitalize() MethodThe capitalize() method in Python is used to convert the first character of a string to uppercase and the rest to lowercase.
This method is useful when you want to format strings to look like proper sentences or names.
string.capitalize()
text = "hello world"
print(text.capitalize())
Hello world
text = "PYTHON IS FUN"
print(text.capitalize())
Python is fun
text = "Python programming"
print(text.capitalize())
Python programming
text = "123hello"
print(text.capitalize())
123hello
Note: Only the first letter is affected. If the first character is not a letter, nothing changes.
No. Strings in Python are immutable. capitalize() returns a new string and does not change the original one.
title() instead.capitalize() is often used in string normalization or preprocessing tasks before comparison or display.
capitalize() returns a new string with the first character uppercase and the rest lowercase.Write a program that takes a sentence as input and prints the capitalized version.
sentence = input("Enter a sentence: ")
print("Capitalized:", sentence.capitalize())
Connect what you noticed in the example with the idea below.
capitalize() returns a string with its first character titlecased and the remaining characters lowercased.
capitalize() makes the first letter of every word uppercase.
This is the misconception to avoid.Reference checks are optional and do not count toward course progress.