Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
Nim /
20180617lsequenceA sequence in Nim is similar to Python's list. It's a dynamic array. import strformat import strutils var names = @["Alice", "Bob", "Cecile"] for name in names: echo name echo names.len() for idx, name in names: echo &"{idx}) {name}" names.add("Daniel") echo names echo "Bob" in names echo names.join(" -> ") Output: Alice Bob Cecile 3 0) Alice 1) Bob 2) Cecile @["Alice", "Bob", "Cecile", "Daniel"] true Alice -> Bob -> Cecile -> Daniel Create an empty sequenceimport strutils var nums = newSeq[int]() echo nums nums.add(12) nums.add(4) echo nums echo nums.join("; ") # the elems will be converted to strings automatically Output: @[] @[12, 4] 12; 4 |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |