Back
For comparing two strings, you need to first declare your string variables and then use the following operators for comparison:
name1 = 'Henry'name2 = 'henry'name3 = 'shawn'name4 = 'Shawn'print("Are name1 and name 2 equal?")print (name1 == name2)print("Are name and name3 different?")print (name1 != name3)print("Is name1 less than or equal to name2?")print (name1 <= name2)print("Is name3 greater than or equal to name 2?")print (name3 >= name2)print("Is name4 less than name1?")print (name4 < name1)
name1 = 'Henry'
name2 = 'henry'
name3 = 'shawn'
name4 = 'Shawn'
print("Are name1 and name 2 equal?")
print (name1 == name2)
print("Are name and name3 different?")
print (name1 != name3)
print("Is name1 less than or equal to name2?")
print (name1 <= name2)
print("Is name3 greater than or equal to name 2?")
print (name3 >= name2)
print("Is name4 less than name1?")
print (name4 < name1)
The output:
Are name and name 1 equal?FalseAre name and name3 different?TrueIs name less than or equal to name2?TrueIs name3 greater than or equal to name 2?TrueIs name4 less than name?False
Are name and name 1 equal?
False
Are name and name3 different?
True
Is name less than or equal to name2?
Is name3 greater than or equal to name 2?
Is name4 less than name?
If you are looking for an online course to learn Python, I recommend this Python Certification program by Intellipaat.
31k questions
32.8k answers
501 comments
693 users