Python beinhaltet 43 Übungen
Titel: Imitation statische Variablen (statisch) ein weiterer Fall.
Programmanalyse: Demonstration der Verwendung eines Python - Rahmen
Source Code:
#!/usr/bin/python # -*- coding: UTF-8 -*- class Num: nNum = 1 def inc(self): self.nNum += 1 print 'nNum = %d' % self.nNum if __name__ == '__main__': nNum = 2 inst = Num() for i in range(3): nNum += 1 print 'The num = %d' % nNum inst.inc()
Das obige Beispiel Ausgabe lautet:
The num = 3 nNum = 2 The num = 4 nNum = 3 The num = 5 nNum = 4