Python Checking a string's first and last character

后端 未结 4 1430
南方客
南方客 2020-12-24 10:33

can anyone please explain what is wrong with this code?

str1=\'\"xxx\"\'
print str1
if str1[:1].startswith(\'\"\'):
    if str1[:-1].endswith(\'\"\'):
               


        
4条回答
  •  猫巷女王i
    2020-12-24 11:01

    When you set a string variable, it doesn't save quotes of it, they are a part of its definition. so you don't need to use :1

提交回复
热议问题