QuestionQ14

VerifiedPython Basics for Data Analysis

You are handling city names submitted by users. These names can include inconsistent capitalization and unwanted spaces.

To standardize the data, you need to:

  • Remove any whitespace at the beginning or end, and
  • Capitalize the first letter of every word (for example, change "new york" to "New York").

For example:

  • "New york " → "New York"
  • "lOS ANGELES" → "Los Angeles"

You have a variable, city, that contains the raw input.

Which line of code correctly updates cleaned_city to perform the required transformation? Select the best answer.

Explanation

Python’s strip() removes whitespace from the beginning and end of a string, and title() converts the string to title case by capitalizing each word. Chaining them produces standardized city names such as "New York" and "Los Angeles".

Community Discussion

No comments yet. Be the first to start the discussion!