|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Mutable or immutable?In Python, a string is immutable. In Nim, a string can be mutable ( Immutablelet s = "hello" echo s # "hello" echo s[0] # 'h' s[0] = 'H' # ERROR! Like in Python. Mutablevar s: string echo s # "" , empty string s.add("hello") echo s # "hello" s[0] = 'H' echo s # "Hello" s.add(" World!") echo s # "Hello World!" As you can see, it also works as a stringbuffer! We don't need a special StringBuffer type in Nim. Just use a mutable string for this purpose. |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |