1. 本人的電腦是14年的MAC ,所以每次打開PyCharm 都很慢,讓我懷疑是否 PyCharm 安裝錯誤。
2. 創建新的python 項目:
- python菜單 -> File -> New Project...
3. Location:
- 項目存儲的位置:如 /Users/用戶名/Desktop/untitled1
4. Interpreter:
- 項目使用的 Python 的版本號:如Python3 , Python2.7 (Mac默認是2.7)
5. 定義函數:
- python 的函數
-
def foo(): # 這里不能 不縮進,因為沒有花括號進行 保護。只有 縮進來規定語法 print("hello world") # 函數調用 foo()
- Swift 的函數
func foo() { print("你好") }
6. 變量的定義與賦值
- Python : 解釋性語言且具有強類型轉換能力,所以不需要申明變量名與變量類型,而是直接給變量賦值即可
-
# 動態語言 s = 1 print(type(s)) s = '1' print(type(s)) s = None print(type(s)) s = True print(type(s)) # type : 查看變量類型
- Swift : 強類型語言
-
var i = 0 let i = 4 // var 變量 // let 常量 // i = 0 Int 類型 // i = "string" String 類型 ...
7. if 語句
- Python
-
def foo(): a = 10 if a > 10: print("hello 10+") elif 5 < a <= 10 : print("hello 5+") else : print("low") foo()
- false : False or {} or [] or () or None or "" or 0
- Swift
-
let i = 10 if i > 10 { print("hello 10+") }else if i > 5 && i <= 10 { print("hello 5+") }else { print("low") }
8. for in 循環
- Python : 只能循環 迭代器:
- 元祖,字典,列表
-
# range -> 自動生成 數組 # range(100) -> 自動生成 0 - 99 個數字 # 獲取數字索引 for i in range(100): print(i)
9. 類的關鍵字:
- Python:
class Foo(object):
- Swift
-
class Foo: NSObject { }