Articles

Program to rewrite a sentence in toggle case in Python

Program to rewrite a sentence in toggle case in Python


In the python programming article, we are going to learn

  • program to rewrite a sentence to toggle case in python

Program to rewrite a sentence to toggle case in Python

The program is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

string = input("Enter a sentence: ").strip()
listed_string = string.split(" ")

new_sentence = ""

for i in listed_string:
    new_word = ""
    new_word += i[0].lower()
    new_word += i[1:].upper()
    new_word += " "
    new_sentence += new_word

print("The sentence is:",new_sentence)

The output of the program is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a sentence: Python is a programming language
The sentence is: pYTHON iS a pROGRAMMING lANGUAGE

Few important tips about the program

1. In toggle case, first letter of each word is in lower case, rest of the letters are in upper case.

2. Here, we have used the concept of indexing and slicing to get the job done.

 

rewrite-a-sentence-to-toggle-case-in-python

 


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Oct 13,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!