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.