In the following Python code:
>>> s1 = 'Hello'
>>> s2 = 'Hello'
>>> s2 is s1
If I compare Var1 is Var2 in a conditional statement if fails to give the correct answer but if i write Var1 == Var2 instead, it returns true. Why is that happening?
is is used for identity testing and == is used for equality testing, i.e, is is the id(a) == id(b).
So your code will be emaluated in the following way:
>>> a = 'hi'
>>> b = ''.join(['h', 'i'])
>>> a == b
>>> a is b
Convert both the strings to either uppercase ...READ MORE
In python objects/variables are wrapped into methods ...READ MORE
There is an efficient way to write ...READ MORE
For Python 3, try doing this:
import urllib.request, ...READ MORE
Use , to separate strings and variables while printing:
print ...READ MORE
For a better understanding you can refer ...READ MORE
suppose you have a string with a ...READ MORE
if you google it you can find. ...READ MORE
In this case, you can use the ...READ MORE
my_list = [1,2,3,4,5,6,7]
The same works for ...READ MORE