恭喜!

Python for Developers 入门

Jasmin Ludolf

Senior Data Science Content Developer

第 1 章回顾

# Define quantity
quantity = 10

# Single quotes ingredient_name = 'pasta'
# Double quotes also work ingredient_name = "pasta"
Python for Developers 入门

第 2 章回顾

ingredient_name = "Basil Leaves"


# Convert to lowercase ingredient_name = ingredient_name.lower()
# List of ingredients
ingredients = ["pasta", "tomatoes", "garlic",
               "basil", "olive oil", "salt"]

# Get the value at the first index ingredients[0]
# Creating a dictionary
recipe_dict = {"pasta": 500,
               "tomatoes": 400, 
               "garlic": 15,
               "basil": 20, 
               "olive oil": 30,
               "salt": 5}
# Create a set
ingredients_set = {"pasta", "tomatoes", "pasta", 
                   "basil", "garlic", "olive oil",
                   "salt"}

# Create a tuple serving_sizes = (1, 2, 4, 6, 8)
Python for Developers 入门

第 3 章回顾

运算符 功能
== 等于
!= 不等于
> 大于
>= 大于等于
< 小于
<= 小于等于
关键字 功能 用法
if 条件满足则执行 流程中的第一步
elif 否则再判断条件 if 之后
else 以上都不满足则执行 elif 之后
Python for Developers 入门

第 3 章回顾

# Ingredients list
ingredients = ["pasta", "tomatoes", "garlic", "basil", "olive oil", "salt"]


# Loop through and print each ingredient for ingredient in ingredients:
print(ingredient)
pasta
tomatoes
garlic
basil
olive oil
salt
Python for Developers 入门

第 3 章回顾

ingredients_to_add = 5
items_added = 0

while items_added < ingredients_to_add:
    items_added += 1
    remaining = ingredients_to_add - items_added

    if remaining > 3:
        print("Several ingredients remaining")
    elif remaining >= 1:
        print("Almost done!")
    else:
        print("Shopping list complete!")
Python for Developers 入门

第 3 章回顾

关键字 功能
and 评估多条件是否都为真
or 评估是否有任一条件为真
in 判断值是否在数据结构中
not 判断值是否不在数据结构中

 

  • list.append()
Python for Developers 入门

后续步骤

  • 其他内置函数

    • zip()
    • enumerate()
  • 包与模块

    • os
    • time
    • venv
    • pandas
    • requests
    • numpy
  • 编写自定义函数

$$

  • DataCamp 的 Intermediate Python for Developers 课程
Python for Developers 入门

恭喜!

Python for Developers 入门

Preparing Video For Download...