Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Nim2
* Scala


[ edit | logout ]
[ sandbox | passwd ]

How an immutable string differs from Python

In Python, a string is immutable. In Nim, a let string is also immutable. But there is an important difference:

The diff
s = "aaaa"
# s[0] = "B"  # ERROR: immutable

# The string is immutable => the string cannot be changed.
# However, `s` is a reference and it CAN point
# to another string object:

s = "bbbb"
print(s)  # bbbb
let s = "aaaa"

#s[0] = 'B'    # ERROR: immutable

#s = "bbbb"     # ERROR

# The string itself is protected, cannot be changed,
# and `s` is also protected: it cannot point
# to another string.

#let s = "bbbb"    # ERROR: cannot be redefined

In Python, s is a reference (a pointer) that can point anywhere. However, the pointed string is protected; the pointed string cannot be modified.

In Nim, when you make a let variable, then everything is protected. The pointed value (or object) cannot be modified, and if your variable is a pointer, then it cannot point anywhere else.

More accurately: in Nim, you bind a variable name to a value. The value is protected and cannot be modified, and the name cannot be rebound to another value. (The value can have a primitive type or it can be an object).

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 April 06, 14:49