• Register
0 votes
32 views

I am new to python programming. I was trying to compare two strings, I wrote a code to compare:

YourStr = "one"
MyStr = "one"

if YourStr = MyStr 
  print("Two strings are same")
else
  print("Two strings are not same")

But it gives an error:

File "main.py", line 4
    if YourStr = MyStr
               ^
SyntaxError: invalid syntax

Whats wrong in my code and how can I compare two string but it is not case sensitive?

10 7 2
6,050 points

1 Answer

–1 vote
 
Best answer

In python programming if you use if or else statement you have to do like

if your condition :

so you should have written like:

If YourStr = MySrt:

And the error you are having beacuse you have put a single = in your code but for your comparison you should have to :

If YourStr == MyStr:

And you should have written your code like;

YourStr = "one"
MyStr = "one"

if YourStr == MyStr: 
  print("Two strings are same")
else:
  print("Two strings are not same")

And you can use 

.lower() 

for your case sensitive issue

11 6 4
34,930 points

Related questions

0 votes
1 answer 16 views
16 views
I am new to python programming I was trying to check if a letter is uppercase in python. I wrote some code to check this statement : import string def UpperCase(s_str): for x in s_str: if x not in string.UpeerCase: return False return True But I can not get the actual ... last): File "<stdin>", line 1, in <module> NameError: name 'LoWWE' is not defined Can anyone help me to solve this thing?
asked Mar 14 LizzyM 6.1k points
0 votes
1 answer 9 views
9 views
I need a program that will print next to last word of a sentence
asked Sep 22 Daniel Anderson 4k points
1 vote
1 answer 22 views
22 views
Problem: I am new in pyhton programing language . I was trying to check if two strings are anagrams python. But I fail repitedly. The code I wrote to check if two strings are anagrams is: def IsAnagram(str1,str2): str1 = input("Enter your first string : ") ... , line 4 str1 = input("Enter your first string : ") ^ IndentationError: expected an indented block What is the problem can anyone tell?
asked Apr 2 LizzyM 6.1k points