String and integer comparison in Python
In this article, we will see how to do string and integer comparison in python.
To understand this lets see an example.
Here we are comparing if value of “x” variable is equal to 2 or not and if the string variable “y” has compared string value.
Comparing Integer and String in Python
user@ngelinux$ cat operator.py #!/usr/local/bin/python3 x=2 y="ngeLinux" ### First x is compared if equal to 2 if x==2: print("x is 2") else: print("x is not equal to 2") ### Now lets try to compare the string y if y == "ngelinux": print("Case insensitve comparision") else: print ("Case sensitive comparision") user@ngelinux$
Output
user@ngelinux$ ./operator.py x is 2 Case sensitive comparision user@ngelinux$