How to Display the Larger String in Python


In this example, we will learn how to receive two strings without using built-in functions and display a larger string in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

str1 = input("Please input the first string: ")
str2 = input("Please input the secondstring: ")
if str1 > str2:
    print("The larger string is: ", str1)
elif str1 == str2:
    print("Two strings are equal.")
else:
    print("The larger string is: ", str2)

Output:

Please input the first string: hello
Please input the second string: world
The larger string is: world
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement