FINLAB

01

Oct 5th, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. '''
  2. 1. 布林(Boolean)
  3. '''
  4. x = True
  5. print(x)
  6. type(x)
  7.  
  8. '''
  9. 2. 整數
  10. python2: -2,147,483,648~2147483647 (32bits)
  11. python3: 任何大小且不會發生溢位(可盡情處理超大數字)
  12. '''
  13. x = 10
  14. print(x)
  15. type(x)
  16.  
  17. '''
  18. 3. 浮點數(含小數點的數字)
  19. '''
  20. x = 3.1416
  21. print(x)
  22. type(x)
  23. round(x,3) #取小數點第幾位,四捨五入
  24.  
  25. '''
  26. 4. 字串
  27. '''
  28. x = 'Hello'
  29. print(x)
  30. type(x)
  31.  
  32. '''
  33. 5. 基本運算
  34. '''
  35. 1+2
  36. 1-2
  37. 1*2
  38. 1/2
  39. 3//2 ##無條件捨去
  40. 3**2 ##次方
  41. 10%3 #mod
  42.  
  43. '''
  44. 6. 比較運算子 comparison operator
  45. 等於 ==
  46. 不等於 !=
  47. 大於 >
  48. 大於等於 >=
  49. 小於 <
  50. 小於等於 <=
  51. '''
  52.  
  53. '''
  54. 7. 邏輯運算子
  55. and, or ,not
  56. '''
  57. (4>3) and (3>4) #需兩個條件都對才成立
  58. (4>3) or (3>4) #一個條件對,即成立
  59.  
  60. '''
  61. 8. 變數轉換
  62. '''
  63. str(99.2) #將浮點數轉為字串
  64. int('100') #將字串轉為整數
  65. float('193.2') #將字串轉為浮點數
Advertisement
Add Comment
Please, Sign In to add comment