# DAY 7
0

## Hello World

if name == 'main':

``````if __name__ == '__main__':
...
...
``````

## Numbers

• int
• float
• complex

• + - * / 加減乘除
• // 無條件捨去除法
• % 餘數
• ** 次方

Built-in function

• abs(x) 絕對值
• int(x) 將x轉型為整數
• float(x) 將x為浮點數
• pow(x,y) x的y次方

## String

• ' ' 單引號
• " " 雙引號
• """ """ 三引號 (文本)
PS: 使用單引號時若要輸出單引號，須輸入\'
``````>>> '"Isn\'t," she said.'
'"Isn\'t," she said.'
>>> print('"Isn\'t," she said.')
"Isn't," she said.
>>> s = 'First line.\nSecond line.'  # \n means newline
>>> s  # without print(), \n is included in the output
'First line.\nSecond line.'
>>> print(s)  # with print(), \n produces a new line
First line.
Second line.
``````

• ' 單引號
• \t tab
• \r\n 換行符號 return

`r'C:\some\name'`

``````"abc" + "def"
"abc"*3 + "def"
``````

``````s = 'abcdefghijklmn'
s #第三個字元
s[-1] #倒數第一個字元
``````

Slice [開始:結束:step]

``````s = 'abcdefghijklmn'
s[0:6:2] #[開始:結束:step]
``````

string format
print(name + " is " + age + " year's old.") 改寫為 string format

"%s..."%(變數)

``````name  = "Jack"
age = "17"
"%s is %s year's old."%(name, age)
``````

"{}...".format(變數)

``````name  = "Jack"
age = "17"
"{} is {} year's old.".format(name, age)
``````

f"{變數}..."

``````name  = "Jack"
age = "17"
message = f"{name} is {age} year's old."
``````

Built-in function
`len(s)`
`dir(s)`

string method

30天學會Python30