Python Program to convert string in Sentence case

By | August 16, 2019

Task: Write a Python Program to convert string in Sentence case. This python programming tutorial will explain the logic of the progrm. The program will take input string and converts it into Sentence case.

For example it will convert the input string – ‘how are you?’ into ‘How are you?’

The Source Code of Python Program to convert string in Sentence case

# Write a Python program to
# input a string and change its
# case to Sentence case using capitalize()
# function. It will convert only the first
# (beginning)lower case letter to upper case.
# it will capitalize only first letter
# of a Sentence.
# The user will enter String
# during program execution

# Start of the Python program

# display message to enter string
# and get input string
str1 = input("Enter a string to convert into Sentence case:")


# use capitalize() method
sentence_string = str1.capitalize()

# now print UPPER CASE string
print(str1, "In sentence case =", sentence_string)

The output of the program

Enter a string to convert into Sentence case:hello python world.
hello python world. In sentence case = Hello python world.

Enter a string to convert into Sentence case:pakistan! we love you.
pakistan! we love you. In sentence case = Pakistan! we love you.

Leave a Reply

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