Erlang - 第n个元素



返回列表的第 N 个元素。

语法

nth(N,List)

参数

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

  • Lst − 元素列表。

返回值

返回列表的第 Nth 个元素。

例如

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

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

输出

运行以上程序时,将得到以下结果。

2
erlang_lists.htm
广告

© . All rights reserved.