Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Introduction to Lists | Lists
Python Ninja (copy - for upload test)
セクション 7.  1
ninja.py

ninja.py

index.html

index.html

preset.py

preset.py

Introduction to Lists

メニューを表示するにはスワイプしてください

Python lists are like containers that can hold different items, such as numbers, words, or objects. You can create a list by enclosing items in square brackets [] and easily add new items to a list using append(), which puts them at the end.

123456789
# Create a list with initial items inventory = ["cat", "monkey"] # Add a new item to the end of the list inventory.append("dog") # Print the updated list print("Updated Inventory:", inventory)

Also you can remove items from the list by using pop(index). This method removes and returns the element at the specified position. If no index is specified, it removes the last item.

1234567891011121314
# Existing list inventory = ["cat", "dog", "chicken", "monkey"] # Get the values last_item = inventory.pop() second_item = inventory.pop(1); # Print the accessed items print("Last item:", last_item) print("Second item:", second_item) # Print the updated list print("Updated Inventory:", inventory)

In the same way, the ninja's inventory is implemented and can hold values like cat, dog, chicken, monkey, parrot, pig, etc.

You can control it using the following methods:

  • pick_to_inventory(index): Picks up an item and places it in the inventory at the specified index, or adds it to the end if no index is provided.
  • put_from_inventory(index): Takes an item from the inventory by index and places it on the map. If no index is provided, it takes the last item.

Remember that indexing in a list starts from 0, which means the index of the first element is 0, the second is 1, the third is 2, and so on.

Here is an example where the ninja collects two animals into the inventory and then places the first element back on the map.

ninja.py

ninja.py

index.html

index.html

preset.py

preset.py

タスク

スワイプしてコーディングを開始

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 7.  1
ninja.py

ninja.py

index.html

index.html

preset.py

preset.py

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt