Conversion and Comparison

Learn about string conversion and comparison in Python.

String conversions

Two types of string conversions are frequently required:

  • Converting the case of characters in a string.
  • Converting numbers to a string and vice versa.

Case conversions

Case conversions can be done using the following str methods:

  • upper(): Converts string to uppercase.
  • lower(): Converts string to lowercase.
  • capitalize(): Converts the first character of a string to uppercase.
  • title(): Converts the first character of each word to uppercase.
  • swapcase(): Swaps cases in the string.

Get hands-on with 1400+ tech skills courses.