• Register
0 votes
108 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,060 points

Please log in or register to answer this question.

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,950 points

Related questions

0 votes
1 answer 2 views
2 views
Problem: How can I do case insensitive string comparison in Python?
asked Mar 31 ummesalma 25.2k points
0 votes
1 answer 4 views
4 views
Problem: Hello ... Can anyone tell me that why I got this error? how to use ignore case in java
asked Mar 26 Ifra 24.4k points
0 votes
1 answer 25 views
25 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, 2020 LizzyM 6.1k points
0 votes
1 answer 68 views
68 views
I need a program that will print next to last word of a sentence
asked Sep 22, 2020 Daniel Anderson 4k points
1 vote
1 answer 38 views
38 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, 2020 LizzyM 6.1k points
0 votes
1 answer 4 views
4 views
Problem: how to I Solve this: check if two strings are anagrams python HELP! I need help understanding this: check if two strings are anagrams python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 10 Mashhoodch 13k points
0 votes
1 answer 33 views
33 views
I am new to python programming.. I was trying to check if a string is empty or whitespace in a code : Mystr= "" Yourstr = " " print ("This string is empty : ", end = "") if(not Yourstr): print ("Yes") print ("This string is empty : ", end = "") if(not Mystr): print ("No") It&rsquo;s output is : This string is empty : This string is empty : No Its not giving me actual result what can I do now?
asked Mar 16, 2020 LizzyM 6.1k points