Comparing Strings in Python
Comparing Strings:
In Python, Comparing Strings using relational or comparison operators such as >, <, <=, etc. Some Comparing Strings are given below:
Operator | Description |
(==) | If two strings are equal, it returns True. |
!= or <> | If two strings aren't equal, it returns True. |
> | If the first string is greater than the second, it returns True. |
< | If the second string is greater than the first, it returns True. |
>= | If the first string is greater than or equal to the second, it returns True. |
<= | If the first string is greater than or equal to the first, it returns True. |
Iterating String:
Iterating String is a sequence type (sequence of characters). You can iterate through the string using a loop as given below:
Example:
str1="Welcome to Webeduclick!" for i in str1: print(i, end=' ')
Output:
W e l c o m e t o W e b e d u c l i c k!