How to compare strings in Python

4 Answers

0 votes
s1 = 'Python'
s2 = 'PHP'

print(s1 == s2)
print(s1 != s2)
print()
print(s1 > s2)
print(s1 < s2)
print()
print(s1 >= s2)
print(s1 <= s2)
  
  
  
  
'''
run:
  
False
True

True
False

True
False
  
'''

 



answered Apr 13, 2021 by avibootz
0 votes
s1 = 'Python'
s2 = 'PHP'

print(s1 is s2)

  
  
  
'''
run:
  
False

'''

 



answered Apr 13, 2021 by avibootz
0 votes
s1 = 'PYTHON'
s2 = 'python'
 
print(s1 == s2)
print(s1 != s2)
print()
print(s1 > s2)
print(s1 < s2)
print()
print(s1 >= s2)
print(s1 <= s2)
   
   
   
   
'''
run:

False
True

False
True

False
True

'''

 



answered Feb 28, 2023 by avibootz
0 votes
from numpy import char

s1 = 'PYTHON'
s2 = 'python'
 
print(char.equal(s1, s2))

   
   
'''
run:

False

'''

 



answered Feb 28, 2023 by avibootz

Related questions

1 answer 146 views
1 answer 112 views
1 answer 151 views
1 answer 110 views
2 answers 181 views
2 answers 150 views
...