Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- 1. 布林(Boolean)
- '''
- x = True
- print(x)
- type(x)
- '''
- 2. 整數
- python2: -2,147,483,648~2147483647 (32bits)
- python3: 任何大小且不會發生溢位(可盡情處理超大數字)
- '''
- x = 10
- print(x)
- type(x)
- '''
- 3. 浮點數(含小數點的數字)
- '''
- x = 3.1416
- print(x)
- type(x)
- round(x,3) #取小數點第幾位,四捨五入
- '''
- 4. 字串
- '''
- x = 'Hello'
- print(x)
- type(x)
- '''
- 5. 基本運算
- '''
- 1+2
- 1-2
- 1*2
- 1/2
- 3//2 ##無條件捨去
- 3**2 ##次方
- 10%3 #mod
- '''
- 6. 比較運算子 comparison operator
- 等於 ==
- 不等於 !=
- 大於 >
- 大於等於 >=
- 小於 <
- 小於等於 <=
- '''
- '''
- 7. 邏輯運算子
- and, or ,not
- '''
- (4>3) and (3>4) #需兩個條件都對才成立
- (4>3) or (3>4) #一個條件對,即成立
- '''
- 8. 變數轉換
- '''
- str(99.2) #將浮點數轉為字串
- int('100') #將字串轉為整數
- float('193.2') #將字串轉為浮點數
Advertisement
Add Comment
Please, Sign In to add comment