close

1.註解

一行註解使用#

 

一個區塊註解

EX:

"""

comment

"""

2.變數

直接打變數名稱,不需要宣告

 

3.Show在螢幕上

print

4.布靈函數

a=True

b=False

(第一個字母必須大寫)

 

5.反斜線\

反斜線\可以將字串中的字串符號'取消其功能

EX:

'There's a snake in my boot!'

上方紅色部分將會使字串結束

所以使用反斜線\即可避免這個情況

'There\'s a snake in my boot!'

反斜線也可以用在單行程式太長時換行用

 

6.字串相關函數

  1. len()
  2. 字串中有幾個有幾個字
  3. EX:
  4. print len("parrot")#the answer is 5!
  5. lower()
  6. 字串中的字全小寫
  7. EX:
  8. "Ryan".lower()
  9. upper()
    1. 字串中的字全大寫
  10. str()

將不是字串的element轉為字串

EX:

str(2)

將會把 2 轉成 "2"

upper()及lower()前面都要加"."符號,這是因為此兩個函數只對字串有用

而len()及str()則對其他資料形式也有效用

7.%s以及%

預先設定變數於字串中,能隨設定改變進而改變字串中特定字

EX:

string_1 = "Camelot"
string_2 = "place"

print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)

%會以括號中的字串依序來取代%s

 %s代表替換字串

%f代表替換具浮點之數字

%d代表替換整數數字

 8.基礎計算符號

Ex:

  1. 1.等於 (==)
  2. 2.不等於(!=)
  3. 3.小於 (<)
  4. 4.小於等於 (<=)
  5. 5.大於 (>)
  6. 6.大於等於 (>=)

 9.BOOLEAN運算

and、or和not


Boolean Operators
---------------------------
True and True is True
True and False is False
False and True is False
False and False is False

True or True is True
True or False is True
False or True is True
False or False is False

Not True is False
Not False is True

 

重要性:NOT>AND>OR

 

arrow
arrow
    全站熱搜

    Joseph Lin 發表在 痞客邦 留言(0) 人氣()