can anyone please explain what is wrong with this code?
str1=\'\"xxx\"\' print str1 if str1[:1].startswith(\'\"\'): if str1[:-1].endswith(\'\"\'):
You should either use
if str1[0] == '"' and str1[-1] == '"'
or
if str1.startswith('"') and str1.endswith('"')
but not slice and check startswith/endswith together, otherwise you'll slice off what you're looking for...