🔤

String Case Methods in Python

Oct 6, 2025

Overview

This lecture explains various string methods in Python used to change the case of text and check for case formatting.

The upper() Method

  • The upper() method converts all letters in a string to uppercase.
  • Syntax: string.upper()
  • Example: "hello I am just preet".upper() results in "HELLO I AM JUST PREET".
  • Method does not take any arguments; parentheses are required.

The lower() Method

  • The lower() method converts all letters in a string to lowercase.
  • Syntax: string.lower()
  • Example: "Hello I am just preet".lower() results in "hello i am just preet".

The capitalize() Method

  • The capitalize() method returns a string with the first character uppercase and the rest lowercase.
  • Syntax: string.capitalize()
  • Example: "maruti Suzuki".capitalize() results in "Maruti suzuki".
  • If the first character is not a letter (e.g., a digit), the string remains unchanged.

The isupper() Method

  • The isupper() method returns True if all letters in the string are uppercase; otherwise, it returns False.
  • Syntax: string.isupper()
  • Example: "HELLO".isupper() returns True; "Hello friends".isupper() returns False.
  • This method returns a Boolean value, unlike upper() which returns a string.

The islower() Method

  • The islower() method returns True if all letters in the string are lowercase; otherwise, it returns False.
  • Syntax: string.islower()
  • Example: "hello".islower() returns True; "HELLO FRIENDS".islower() returns False.
  • This is the opposite of the isupper() method.

Key Terms & Definitions

  • Uppercase — Letters in capital form (A, B, C...).
  • Lowercase — Letters in small form (a, b, c...).
  • Boolean value — Data type with only two values: True or False.
  • String method — A function that can be used on a string object.

Action Items / Next Steps

  • Practice using each method (upper(), lower(), capitalize(), isupper(), islower()) in the Python interpreter.
  • Experiment with sample strings to observe each method's effect.