如果变量中的某个单词被拆分等于python中的文本字符串,如何返回true

我有一个名为newSong的文本字符串,其中包含两个实例变量( title,artist),如下所示:

newSong = Song ("Rum and Raybans","Sean Kingston and Cher Lloyd")

我有一个名为checkIfArtistExists(self,artist)的方法 我的任务是使用split,for循环和if语句。 我必须拆分艺术家,所以如果艺术家的名字由肖恩,金斯顿,雪儿,劳埃德组成,它将返回true,否则返回false。

我是编程新手,逻辑也不是很好。有人可以给我建议或建议吗?


class Songs(object):

   def __init__(self,tittel,artist):

        #Instanse variabler

        self._tittel = tittel

        self._artist = artist

  def  CheckIfArtistExists(self,artist):


       names = artist.split()

       for n in names:
           if n in artist:
              return true
           else:
             return false

newSong = Song ("Rum and Raybans","Sean Kingston and Cher Lloyd")

assert(newSong.CheckIfArtistExists("Sean Kingston and Cher Lloyd"))
chengnuo2020 回答:如果变量中的某个单词被拆分等于python中的文本字符串,如何返回true

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3158471.html

大家都在问