Check If Two Strings Are Equal using Python Use == operator to test if two given strings are equal or not. You can use != as not equal to operator. It returns false if string matches. Example In this example, we initialize two variable with sting and compare if both stings are equal or not.
| x = "Hello" y = "Hello" if x == y: print("Equal") else: print("Not equal") |
Output: Equal Another Example Here is another sample Python program which will prompt user to enter a strings. Then compare the input string with another predefined string.
| name = "Rahul" x = input("Enter your name to confirm: ") if x == name: print("Match found") fi |
Read More C – If-Else Statement The if-else statements are used to run specific code based on condition. The if statement executes a statement if a specified condition is true. If the condition is false, another statement can be executed. Basically, there are 4 types of if statements. if statement if-else statement if-else-if ladder statement nested if statement 1. if Statement An if statement evaluates the expression written inside the parenthesis. if (Expression) { // statement block } If the expression returns true, The if statement block will be executed. If the…
Read More Bash if else Statment If-else is the decision making statements in bash scripting similar to any other programming. Where execution of a block of statement is decided based on the result of if condition. If it evaluates a condition to true, then if block code is executed, on the false condition, the else block code is executed, which is optional. Syntax:
| if [condition] then //if block code else // else block code fi |
basically, there are 4 types of if statements. if statement if-else statement else-if ladder statement nested if statement 1. Bash – if Statement Example This is the basic…
Read More