HKCT KT night 20250507-0723

Run Settings
LanguagePython
Language Version
Run Command
print("Hello, World!") C:\Users\Your Name>python hello.py Hello, World! import sys print(sys.version) if 5>2: print ("Five is greater than two!") #if 要縮排, 通常4格 print ("Thank you!") #要相同縮排 """ THIS IS A MULTI LINES COMMENTS """ print("Hello World!") print(1+1) #先運算後出值 x=1 y=1 print(id(x)) # 1放在RAMM, X=1 係話比佢聽1在RAM的地址 print(id(y)) x=x+1 # 加優先過等號 y=1.0 print(x) print(id(x),id(y)) print(type(x),type(y)) print(x>0) "" This is a test "" _y=1 #varible only can use_ or letter, double _ build in function print(0.5-0.4) #0.1 會有誤差 print(0.5-0.2) print(0.1+0.1+0.1) #0.3 會有誤差
_y=1 #varible only can use_ or letter, double _ build in function print(0.5-0.4) #0.1 會有誤差 print(0.5-0.2) print(0.1+0.1+0.1) #0.3 會有誤差 from decimal import Decimal #decimal (Library), Decimal (class) from math import * print(globals()) help(sin) x=Decimal("0.1") y=Decimal(0.1) print(x,type(x)) print(y,type(y)) print(sqrt(1+1)) x="Hello" print(type(x),id(x)) print(x[0]) #x[0]=S 因為佢成舊放响RAM, 所以冇得只改一個字母 x="Sello" print(x,id(x)) -------------------- def a(): ''' +++ HELP +++ +++ HELP +++ +++ HELP +++ ''' x=1 help(a) ----------------------------- def a(): x=''' +++ HELP +++ +++ HELP +++ +++ HELP +++ ''' print(x) a() ---------------------------- # \ 係continue line, \後面不能有space x=1+1+1+1+1+1+1+1+ \ +1+1+1 print(x) ------------------------------ x=True #internal 係1 y=False #internal 係0 print(1==True) print(0==False) print(1!=False) print(0!=True) print(True+False) print(x+y) print(x+x) #一個等如用黎做assignment, 兩個等如用黎做比較 x=[1,2,3] y=[4,5,6] --------------------------------------------- #expression_result=7-4+3*6/2**2%5 expression_result=(7-4)+(((3*6)/(2**2))%5) expression_result=((10+(3*2))<20) and ((15%4)==3)) or (not ((5-(3*2))>0)) result = not (10 // 3) == 3 or ((8 %3) +1) == 3 and 7 | 2 > 5 result4 = (5 + 3) (if ((2 ** 3) > 7) else ((4 * 6) (if (7 < 8) else (5 - (10 /2)))) result2 = 10 > 5 and 3 * 3 + 1 <= 10 or not 5 != 5 and 4 * 2 result1 = 3+5**2&15|2**3 if 8%3 >1 else 1^7&4
#PEP8 (optional) # "None" is a special data type #3,8-11 少用 name='PERCY' age=6 print('Hi! '+ name + str(age)) print(f'Hi! ', {name} , {age}) print(type(str(1.0))) print(int(float('1.1'))) print(float(1),float(1.1),float(True)) print(float(1),float(1.1),float(False)) print(bool(1),bool(2.1),bool('a'),bool('')) #不是0就是 True, 空格,None False name=["john","peter","ann","dave"] #list 所有都是地址 print(id(name),type(name)) print(name[0],name[1],name[2],name[3]) name=["john",10,10,None] print(name[0],id(name[1]),id(name[2]),name[3]) name=["john",["john",10,10,None],[1,2,3,4], None] name[2][0]=20 print(name) print (name[2]) print (name[0]) name=["john",["john",['a','b','c'],[[1,2,3]],None]] print(name[1][0][2]) name=["john",["john",['a','b','c'],[[1,2,3]],None]] print(name[1][0][2]) t=1,2,3 print(type(t),t) t=1, print(type(t),t[0]) print(type(t),t[0],t) a,b=1,2 #turple print(a,b) a,b=[1,2],[2,3] #list is address print(a,b) a=[1,2],[2,3] print(a,b) #Tuple a,b=1,2 #tuple a,b = a+b , a*b #a,b = 1+2,1*2 = 3,2 a,b = [a,b],[b,a] #a,b = [3,2] [2,3] #a,b = a #a,b=[3,2] #a,a = a print(a,b) #Tuple #SET 大{} filter 走相同value s = {1,2,3,4,5,6,7,1,2,1,2,1,2,3,3,4,4,4,5,6,6,7,7} print(s) s = {1,2,3,'a',5,6,7,1,2,1,'b',1,2,3,3,4,4,4,5,6,6,7,7} print(s) s = [1,2,3,'a',5,6,7,1,2,1,'b',1,2,3,3,4,4,4,5,6,6,7,7] #把list相同值filter走 print(list(set(s)))
Editor Settings
Theme
Key bindings
Full width
Lines