Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Lists | Other Data Types
/
Introduction to Python
セクション 4.  1
single

single

bookLists

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

Welcome to the exciting world of Python lists! In this chapter, we dive into how lists serve as a versatile tool for managing collections of items, essential for scenarios like organizing product inventories in a grocery store. Through practical applications and video demonstrations, you'll learn to create, manipulate, and apply list methods effectively.

Watch as Alex demonstrates how to create and manipulate lists in our grocery store case.

Fundamentals of Lists

Lists in Python are highly flexible, capable of storing a diverse range of objects, including numbers, strings, and even other lists.

Here's how they work:

Creation

Lists can be created by enclosing comma-separated values in square brackets []. You can also convert iterable objects (like strings, sets, tuples) into lists using the list() constructor.

Ordering

The elements in a list maintain a specific order, which does not change unless explicitly modified using list methods (more on list methods later!).

Mutability (Changeability)

Lists are changeable, allowing you to add, remove, or alter elements after the list has been created.

Allowing Duplicates

Since each element in a list is indexed, the same value can appear multiple times at different positions.

Examples

Here's a simple example of a list containing different types of grocery items:

123
# A list showcasing various grocery categories grocery_items = ["milk", "eggs", "cheese", "butter"] print(grocery_items)
copy

Similar to string indexing, elements inside of a list can also be accessed using index numbers:

Lists also have some flexibility since they are not restricted to a single data type. You can store a combination of different types of data within the same list. You can even store lists within a list:

タスク

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

  • Create a list named fruits containing the elements 'apple', 'banana', and 'cherry' in that order.
  • Print the fruits list.

解答

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

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

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

セクション 4.  1
single

single

AIに質問する

expand

AIに質問する

ChatGPT

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

some-alt