GMJH
2023/07/10
~ 2023/07/13
問都問 🙌
print("Hello World!")
a = 1
bucket = []
其實不快!
應該說是非常慢 🐢
無論如何
每個語言都有優缺點和適用的場域
Python 仍是目前的主流語言 ✅
在寫任何一行 code 之前
先學會要怎麼寫註解!
不然寫完過三天就看不懂了
print("Hello world!") # 輸出 Hello world! , 雙引號不會跟著輸出 , 我寫的第一行 code # 第二行
print("Hello world!") ''' 會輸出: Hello world! 雙引號不會跟著輸出 這是我寫的第一行 code 空了好多行,再一行 '''
print("This is an output with newline")
( 預設就會換行 )
print(3.14)
print(111)
print(False)
,
分開要輸出的東西print("Pi =",3.14)
( 預設會用空白隔開 )
print("End with empty string.",end="")
end="你想要的結尾"
print(1,2,3,sep=",")
sep="你想要的結尾"
,
分隔a = input()
print( type(a) ) # str
user = input("Enter a name:")
food = input("Enter a type of food :")
print(user,"is eating",food)
三角形面積計算機
width
height
Example Input:
5
4
Example Output:
10
+
-
*
/
%
&
連接( 底線 _
可以)while
if
else
…a=1
b =3.210
c123 = False
__12_Jo_= "string obj"
signleQuoteStr = '123'
123ouo = 1
a*b-c = d
if = None
hasCar
coolBlueBigCar
has_car
cool_blue_big_car
盡量把變數命名的有意義!
a=1
ouo="User"
c=False
__123=456
# .... -> confusing 🤯
count = 1
userName = "User"
hasCent = False
money = 456
在專案中用於 設定相關 的變數
大多會命名成 底線搭配全大寫
CLIENT_LIMIT=50
SERVER_NAME="www.jason.com"
WORKER_ENABLE=True
練習一下
看個例子
Python 基礎的資料型態:
str
int
float
bool
byte
NoneType
如何確認資料型態?
如何確認資料型態
print( type(varName) )
num="123"
print( type(varName) ) # str
如何把「字串」轉乘「整數」呢?
或是
如何把「整數」轉乘「浮點數」呢?
num = 123 num_float = float(num) num_int = int(float('2.79'))
跟一般數學一樣,Python 也可以 +
-
*
/
print(10*5)
a=9
b=7
print(9-7)
print(10*5)
a=9
b=7
print(9-7)
print(5/3)
print(5//3)
print( int(5/3) )
print(5/3) # 1.6666666666666667
print(5//3) # 1
print( int(5/3) ) # 1
現在 a
, n
兩個變數,要計算 a
的 n
次方
# try it your self
不是 ^
是 **
兩個乘號
print(3**5)
有一個在寫程式很常用到的運算子
但國中好像還沒教到
不過概念很簡單
math :
a mod b : a/b 的餘數
programming :
a%b
Example :
16%5 = ?
99%2 = ?
66%3 = ?
不同型態之前可以運算嗎?
print(123*123)
print("123"*123)
print("")
不知道變化
就每行先 print 出來看看!
輸入 a
b
兩個變數,並輸出以下結果
Example output:
a is : 5
b is : 3
The result of a + b is : 8
The result of a - b is : 2
The result of a * b is : 15
The result of a / b is : 1.6666666666666667
The result of a mod b is : 2
The result of a ^ b is : 125
Compiled language
vs
Interpreter language
編譯語言
vs
直譯語言
0
跟1
)那是不是可以
一行一行輸入給直譯器跑 ?
來跟 Python Interpreter 玩一下