Python Program to Convert String to Lowercase

Introduction

Converting a string to lowercase is a common operation in programming, especially when you want to standardize text data for comparison or storage. This tutorial will guide you through creating a Python program that converts a given string to lowercase.

Example:

  • Input: HELLO WORLD

  • Output: hello world

  • Input: Python Programming

  • Output: python programming

Problem Statement

Create a Python program that:

  • Takes a string as input.
  • Converts the string to lowercase.
  • Displays the lowercase string.

Solution Steps

  1. Take Input from the User: Use the input() function to get a string from the user.
  2. Convert the String to Lowercase: Use the lower() method to convert the string to lowercase.
  3. Display the Lowercase String: Use the print() function to display the converted string.

Python Program

# Python Program to Convert String to Lowercase
# Author: https://www.rameshfadatare.com/

# Step 1: Take input from the user
input_string = input("Enter a string: ")

# Step 2: Convert the string to lowercase
lowercase_string = input_string.lower()

# Step 3: Display the lowercase string
print(f"The lowercase string is: {lowercase_string}")

Explanation

Step 1: Take Input from the User

  • The input() function prompts the user to enter a string. The input is stored in the variable input_string.

Step 2: Convert the String to Lowercase

  • The lower() method is used to convert the entire string to lowercase. This method returns a new string with all characters in lowercase.

Step 3: Display the Lowercase String

  • The print() function is used to display the converted lowercase string.

Output Example

Example 1:

Enter a string: HELLO WORLD
The lowercase string is: hello world

Example 2:

Enter a string: Python Programming
The lowercase string is: python programming

Example 3:

Enter a string: LEARNING IS FUN
The lowercase string is: learning is fun

Conclusion

This Python program demonstrates how to convert a string to lowercase using the lower() method. It’s a simple example that helps beginners understand basic string manipulation in Python.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top