• Register
0 votes
62 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 22 views
22 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 15 views
15 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 29 views
29 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 15 views
15 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
0 votes
1 answer 195 views
195 views
Problem: The Python language is not sensitive to block structuring of code.
asked Mar 9, 2020 ArifulIslam 5.6k points
1 vote
1 answer 29 views
29 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29, 2020 LizzyM 6.1k points
1 vote
1 answer 20 views
20 views
Problem: I was tring to find the length of a string in python. So I wrote a code: string = 0 for c in "popular": string+==1 print (string) which gives following error; File "ab.py", line 3 string+==1 ^ SyntaxError: invalid syntax Is this the right way to do this or there are other waysto find this out?
asked Mar 28, 2020 LizzyM 6.1k points