Erlang - nth 方法

返回列表的第 N 个元素。

语法

nth(N,List)

参数

  • N − 从列表中返回的第 n 个值。

  • List − 元素列表。

返回值

返回列表的第 N 个元素。

例如

-module(helloworld). 
-import(lists,[nth/2]). 
-export([start/0]). 

start() -> 
   Lst1 = [1,2,3], 
   io:fwrite("~p~n",[nth(2,Lst1)]).

输出

当我们运行上面的程序时,我们将得到以下结果。

2

❮ erlang_lists.html