关于#python#的问题,请各位专家解答!

img

      Exercises -L4-Q1
      Write Python code that initializes a tuple of
      strings representing different emotions [i.e.,
      happy,sadfear, surprisel.Write code that
      prints the number of elements in the tuple, the
      first elementand the last element.
                                                                                                                            2
      IHint:You can use the len function to
      determine how many elements are in the tuple
      and then use that information to print the last
      element.
Python Programming

首先翻译一下,然后再给代码

编写Python代码初始化的元组
表示不同情绪的字符串[例如,
快乐,悲伤恐惧、惊讶。编写代码,
输出元组中的元素个数
第一个元素和最后一个元素。
你可以使用len函数
确定元组中有多少元素
然后用这些信息打印最后一张
元素。
feel = ("happy", "sad", "fear", "surprise")
print(len(feel)) 
print(feel[0])
print(feel[-1])
'''
len函数返回对象的长度
feel[0]返回feel元组的第一项
feel[-1]返回最后一项
'''