当前位置: 移动技术网 > IT编程>脚本编程>Python > python基础学习(六)

python基础学习(六)

2019年11月18日  | 移动技术网IT编程  | 我要评论

贺龙的孙子,铜锣烧,cocosphier

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

 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网