迹忆客 计算机编程题库

Python 经典面试题 基础部分一

以下代码输出什么? ```python def rev_func(x,length): print(x[length-1],end='' '') rev_func(x,length-1) x=[11, 12, 13, 14, 15] rev_func(x,5) ```
  • 程序运行正常,没有错误。
  • 程序显示15 14 13 12 11。
  • 程序显示11 12 13 14 15。
  • 程序显示15 14 13 12 11然后引发索引超出范围异常。
正确答案是:
正确率:85%

解析:

在rev_func的print语句中,我们使用list x的索引值。 我们减去函数长度的值,因为它成为print语句中x的索引。

查看笔记

扫码一下
查看教程更方便