# Print
---
# outline
1. 註解(comment)
2. 變數
3. type
4. 運算
5. I/O (input and output)
6. How to google
---
# Before Beginning
----
### 把手伸出來

----
## 試試看
```
print(0.1 + 0.2)
```
---
- BBC電視劇——《蒙提·派森的飛行馬戲團》(Monty Python's Flying Circus)的愛好者
----
# Zen of Python
### Python 之禪
----
```
import this
```
[wiki的翻譯](https://zh.wikipedia.org/wiki/Python%E4%B9%8B%E7%A6%85)
---
# 程式運行
----
1. 程式語言
2. 0101011000001
3. 運算
4. 得到執行結果
---
# 介紹完Python後
---
# 註解(comment)
----
## 井字號(#)
## 頭尾三個引號(''' or """)
```
#print("hello")
```
```
'''
print("hello")
'''
```
```
"""
print("hello")
"""
```
----
### 功能
- 補充說明
- 不想刪除程式碼
----
# Question
---
### 變數(variable)and 賦值(=)
----
## 什麼是變數

----
### 可以想像成把值(value)丟到箱子裡
----
#### 直接看code!
```
a = "hello world!"
print(a)
```
----
# 賦值(assign)
### = ?
### == ?
----
- 功能:
1. 新增一個叫做 "a" 的變數
2. 把「hello world」這個字串指派給 "a" 這個變數
----
## 功能
1. 可以存值,方便運算
2. 增加易讀性
----
# 變數名稱的規則
----
- 變數名稱的開頭必須是字母或者底線,不能以數字開頭
- 變數名稱只能包含字母、數字與底線 (A-z, 0-9, _ )
- 變數名稱的大小寫不一樣則被視為不同變數 (age, Age 和 AGE 是三個不一樣的變數)
- 不能是if,else,while等關鍵字
- 不要用函數名稱當變數名字
----
### 哪些變數名稱不合法
- zen-of-python
- print
- 111
- (1)
- -.-
- ?!
- _n
----
### print 和 _n 都是可以的,但前者不建議,後者有其他用處
----
# Question
---
# 運算子
----
```
print(1+1)
```
----
```
a = 5
print(-a)
```
----
[更多運算子](https://www.w3schools.com/python/python_operators.asp)
----
print("hello" + "world")
----
# Question
---
# Data Type
----
# type()
----
```
print(type(1))
```
```
print(type(1.0))
```
```
print(type("sprout"))
```
----
# 什麼是 Data Type
----
- 舉例:int, float, string
- 不同資料型別能做的事會不太一樣
- 就算對他們做同樣的事,也可能會有不同的結果
- 變數會以不同的資料型態儲存資料
----
### try!
```
a = 1 + 1
b = 1 + 1.0
c = "10" + "0"
d = "hello" + "world"
e = ["a","b"] + ["c","d"]
print(type(print))
print(type(type))
print(type(int))
```
----
### 型別轉換
```
a = "1"
a = int(a)
```
```
b = 1
b = str(b)
```
----
### try
```
int(1.5)
int("sprout")
```
----
- 取一個數的小數可以怎麼做呢?
----
```
a = 2.5
b = int(a)
print(a - b)
```
----
# Question
---
# input
----
- 可以輸入什麼?
- 可以用什麼設備輸入
----
## 有完整的輸入輸出,就可以達到互動的效果
----
```
a = input("可寫可不寫的提示訊息")
```
```
name = input("輸入你的名字: ")
print("hello,", name)
```
----
Question and Practice
### 完成它
```
Hi, [name]. You're [age] years old next year.
```
----
```
name = input()
age = int(input())
age = age + 1
# age += 1
age_str = str(age)
print("Hi, " + name + ". You will be " + age_str + " years old next year.")
print("Hi, " + name + ". You will be" , age ,"years old next year.")
```
## print
#### beginning!
----
```
print("hello world")
```
----
### 等等,那函式(functions)是什麼?
----
#### 你可以把它當作一段特別的關鍵字
- 功用:
- 執行特定工作
- 修改參數、引數,重複使用
- 易懂
----
# 繼續print!!
----
- 以下哪些是會出現error的呢?
```
print("hello" )
```
```
print ("hello")
```
```
print("hello");
```
```
print "hello"
```
```
print(hello)
```
----
## answer:第四個、第五個
----
```
print("starburst" "stream")
```
```
print("starburst", "stream")
```

----
```
print("starburst", "stream",sep="!!")
```
----
# end
----
```
print("star", end="")
print("burst", end=" ")
print("stream", end="!")
```
----
# 結合
```
print("starburst", "stream",sep="!!",end=" RRRRRRR")
```
----
# Question and Practice
- 什麼時候會用到end?什麼時候會用到sep?
- 玩玩看 sep 和 end
- 分別用逗號和 sep 達到和下面程式碼一樣的效果
```
print("hello" + "world")
```
---
## print
### 跳脫字元
----
## 試著印出以下這段話
```
"Gura" is a shark
```

----
### 透過反斜線,讓後面的符號、字母有其他意義
```
print("\"Gura\" is a shark")
## 讓gura前後的引號可以顯現
```
```
print("nnn\nnn")
## \n 會換行
```
```
print("ttt\ttt")
## \t 會一次空一個tab
```
```
print("xyz\bc")
## b是backspace,會刪掉前一個字元
```
```
print("xyzxyz\rabc")
```
----
```
\n 是換行的字元
```
```
print(r'\n 是換行的字元')
```
----
# Question and Practice
- 用r會不會有哪裡出問題?
- 什麼時候會用到\r?
----
# 同一個引號會出問題!
```
print(r'hello \nworld')
```
```
print(r'hello 'world')
```
----
# 計時器
```
import time
for i in range(9):
i = 9 - i
i = str(i)
print("\r" + i,end="秒")
time.sleep(1)
print("\r" + "0 秒",end="")
print("\nHappy New Year!!!!")
```
----
```
import time
s = "sprout"
l = len(s)
for i in range(l):
print("\r" + s[:l-1-i] + "_", end="")
# print(".",end="")
time.sleep(1)
print("______")
```
----
```
print("hello world")
print("next line!") # 那怎麼不換行
print("a", "b", "c")
print("a" + "b" + "c")
print("a") # " 和 '有差嗎
print('b')
print("I'm Nuss")
# print('I'm Nuss')
```
----
```
a = "world"
b = "Nuss"
c = f"hello {a}, I am {b}"
d = f"hello {a}, I am {b.lower()}"
print(c)
print(d)
```
----
```
# format的格式用法
import math
print(f'The value of pi is approximately {math.pi:.3f}.')
table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}
for name, phone in table.items():
print(f'{name:10} ==> {phone:10d}')
print(f'The value of pi is approximately {math.pi:07.3f}.')
```
----
---
# 結語
----
綜合練習 & 作業
[neoj 3000](https://neoj.sprout.tw/problem/3000/)
[neoj 3008](https://neoj.sprout.tw/problem/3008/)
[neoj 3009](https://neoj.sprout.tw/problem/3009/)
---
## 如果你遇到困難
1. 在課堂上
----
# 我們超多助教!
----
## 如果你遇到困難
2. 下課後
- 先google看看
- 如果還是無法解決
----
# 我們超多助教!
----
- 截圖
- 告訴我們你做了哪些努力與嘗試
- 網路上可能沒有正解,但一定會有值得參考的資料
---
# How to google
1. - (刪去後面的關鍵字)
- 車子 -廣告
2. "" -> 強調(完全一樣)
3. site
- twitter site:youtube.com
4. related
- related:youtube.com
----
[link](https://support.google.com/websearch/answer/2466433?hl=zh-Hant)
---
# Thanks
{"metaMigratedAt":"2023-06-17T22:37:45.866Z","metaMigratedFrom":"Content","title":"Print","breaks":true,"contributors":"[{\"id\":\"67f64c5d-de88-4a53-9b64-c2cfb2bffa58\",\"add\":6084,\"del\":551}]"}