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结果:

 13.字典

# 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结果:

原文地址:https://www.cnblogs.com/songxiaoke/p/11880835.html