10

# (1)變數型態- 整數或浮點數

## 例子: 計算一天的打工薪水

``````hour_salary = 200              #設定時薪
day_salary = hour_salary * 10  #一天工作十小時
print(day_salary)
``````

## x=x+1 !?

``````x = 5
x = x+1
print(x)
``````

``````x = 5
x += 1
print(x)
``````

(補充說明)

「+」，「-」，「*」，「/」符號要擺在等號前面哦~

# (2)變數型態-字串就是一串文字

## 例子: 打招呼

``````name = "Alice"
greeting="Nice to meet you, "
print(greeting+name) # 用加號把 greeting 和 name兩個字串接起來
``````

# (3)變數型態- list: 能納百物的百寶袋

``````student1 = 'Alice'
student2 = 'Bob'
student3 = 'Cindy'
``````

## 使用列表(list)

``````students = ['Alice', 'Bob', 'Cindy', 'Daisy', 'Eve', 'Fairy']
``````

## 新增元素

``````students = ['Alice', 'Bob', 'Cindy', 'Daisy', 'Eve', 'Fairy']
students += ['Gary'] #列表後面必須串接列表，效果同students = students+['Gary']
print(students)
``````

## 取用資料

``````students = ['Alice', 'Bob', 'Cindy', 'Daisy', 'Eve', 'Fairy']
print(students[0])
print(students[1])
print(students[5])
``````

`Alice`
`Bob`
`Fairy`

python存資料的編號是從0開始，
python存資料的編號是從0開始，
python存資料的編號是從0開始，

## 修改列表內元素

``````students = ['Alice', 'Bob', 'Cindy', 'Daisy', 'Eve', 'Fairy']
print(students) #['Alice', 'Bob', 'Cindy', 'Daisy', 'Eve', 'Fairy']
print(students)#['Ade', 'Bob', 'Cindy', 'Daisy', 'Eve', 'Fairy']
``````

# 課後練習

``````L = [1,2,3,4,5,6,7,8,9,10,11,12,'7','6','5','4','3','2','1']
print(L[?])
``````

### 6 則留言

2
ImQQ
iT邦新手 5 級 ‧ 2019-06-19 00:28:55

Bingo，6是一個答案。

ImQQ iT邦新手 5 級 ‧ 2019-07-02 22:57:36 檢舉

2

iT邦新手 3 級 ‧ 2019-06-19 09:23:48

print(L[6])、print(L[12])都可以有(?

(仔細看的話，print(L[12])並不會把字串的引號也印出來)
Bingo~

1

iT邦大師 1 級 ‧ 2019-06-19 18:37:50

1

iT邦新手 1 級 ‧ 2019-07-01 14:53:05

``````L=[15,'Hello',[1,2,3]] # 例如list裡同時放入數字、字串、list
``````

1
medivh0102
iT邦新手 5 級 ‧ 2020-03-03 01:29:57

name = "medivh"
greet = "HI~"
print ("greet+name")

``````str = '123'
``````

「Restart kernal」選單按下去應該就好了

1
maggiectsai
iT邦新手 5 級 ‧ 2020-03-29 17:15:13

【str是python的內建資料型態，