python基礎學習(六)

12.函數函數

#  函數   function
# def  聲明函數
# 關鍵字  keywords

# print("Hello  ke")

name = "songKE"


# 注意  縮進塊  定義 函數    自上而下
def sayHello(name, age):
    print("Hello" + name + ",age:" + str(age))


# print("say hi")
# print(1)
# 調用函數
# sayHello(name)
# print(2)

# List
friends = ["張三", "李四", "王五"]
ages = [12, 13, 41]
sayHello(friends[0], ages[0])
sayHello(friends[1], ages[1])
sayHello(friends[2], ages[2])

run結果:spa

 

 13.字典code

# dic dict
# key value  鍵 值
# nickname  張三
# age   12
# is_vip    False

# 更新字典  增長新的key value

# 定義 字典變量
customer = {
    "nickname": "張三",
    "age": 12,
    "is_vip": False,
  
}

# print(customer["nickname"])

# 查詢不到  默認返回0000000
print(customer.get("id", "0000000"))

run結果:blog

相關文章
相關標籤/搜索