20250506

Run Settings
LanguagePython
Language Version
Run Command
# Python store value to RAM address on Ref table # In Python, all data are object base. x = 1 y = 1 print(id(x),id(y)) print(print(id(x),id(y))) #Next step print(None) # Show up what variables are stored by dictionary. print(globals()) del x print(globals()) # Test assignment statement in Python. e.g. print(x=1) or print(del x) x = 1; y = 1 ; print(print(id(x))) #Python accept ; to separate statements # Python will accept expression with new lines x = (1 + 1 +1) # \ is line contineouation, after that can't add comments print(x) x = 1 \ +1 \ +1 print(x) x=1 if x==1 \ : x=x+1 print(x) #Python can add comment in expression x = (1+ #comment 1 #comment ) print(x) # Python docstring if x == 1 \ : #comment pass ''' docstring - multiple line comment ''' x = x + 1 print(x) help(print) # When you not sure what is the content of function, you can us Pass statement to skip the error of indentation. x = 1 if x == 1: pass y = 1 # _x is defined as private variable from dio import * #print(_x,y) print(y) a() # __x is class variable # __init__ is Python internal system variables # List variables ll = ["peter","ann","john","ryan"] print(ll[0],ll[1],ll[2],ll[3]) ll[0]="anna" #List is mutable print(ll) # Tuple variable is immutable tt= "peter","ann","john","ryan" print(tt[0]) #tt[0]='dave' #TypeError, ' and " in python means the same, but not Java. # Decomposition. Very handly if you have lots of assignments. a,b = 1,2 print(a,b) a,b,c = 1,2,3+2 print(a,b,c) a,b = a+b, a+c print(a,b,c) a,b = (a,c),(c,a) print(a,b,c) a,b = [(a,c),(c,a)] c,b=a # a,c print(a,b,c) # c+b,b+c = a,b #Return error because we can't assign value to an expression b,b = a,c # b = a ; b = c = (a,c) print(a,b,c) # Fiboni def fib(n): a,b = 0,1 result = () for i in range(n): result += (a,) a,b = b, a+b print(i) return result print(fib(10)) tt=1, #Create Tuple by , without , it's an integer print(tt) from tria import * print(fib(10)) x = 1 print(type(fib),fib,type(x),id(x))
_x = 1 y = 2 def a(): print(_x)
# Why use _ to define for loop variable def fib(n): a,b = 0,1 result = () for _ in range(n): result += (a,) a,b = b, a+b return result
Editor Settings
Theme
Key bindings
Full width
Lines