Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* Adator. prog.
  + feladatsor
  + quick link

Teaching

Prog. for Data Sci.
  ▸ exercises
  ▸ quick link

teaching assets


Félévek

* 2026/27/1
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ✦C++, ✦Clojure, ✦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, and the type of the variable is value type, then everything is protected. The pointed value cannot be modified, and the variable 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. (You get this double protection for value types).

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 July 29, 22:53