environment windows7 (I want a Mac Book Pro 16inch) Visual Studio Code chrome python ver3.8.3
This article is written for beginners in programming and Python.
A list is a thing that puts values (numerical values, character strings) in a box.
How to make that box (list) is the square brackets []
in Python.
I will put a value (numerical value, character string) in this []
.
list.py
[1,2,3,4,5]
['peach','princess','kuppa','mario']
In this way, each value is put in a delimiter (list) with (comma).
Just creating a box (list) will not work, so how to use it is as follows: variable
Use with.
list.py
num_list=[1,2,3,4,5]
mmaker=['peach','princess','kuppa','mario']
print(num_list)
#[1, 2, 3, 4, 5]
print(mmaker)
#['peach', 'princess', 'kuppa', 'mario']
You can put another box (list) in the box (list).
This is called a multiple list
.
Creating a multiple list
is intuitive and easy.
I will make another [] in [].
list.py
['peach', 'princess', 'kuppa',[1, 2, 3, 4, 5], 'mario']
One thing to keep in mind is that you should not forget to write ,
before and after the newly added []
.
Example: Variable name = [1,2,3, [9,8,7],
4,5,6].
list.py
mmaker_num = ["peach", "princess", "kuppa", [1, 2, 3, 4, 5], "mario"]
print(mmaker_num)
#['peach', 'princess', 'kuppa', [1, 2, 3, 4, 5], 'mario']
Boxes (lists) can be used in various ways, but you can also specify the value assigned to a variable as an element. What I'm saying is as follows.
list.py
x='mario'
p='peach'
hero=[x,p]
print(hero)
#['mario', 'peach']
Even if the value assigned to the variable is disturbed (changed) on the way, the value in the box (list) does not change.
list.py
x='mario'
p='peach'
hero=[x,p]
print(hero)
#['mario', 'peach']
x='luigi'
print(hero)
#['mario', 'peach']
fin
Python #Hello World for super beginners
Python for super beginners and super beginners # Easy to get confused
Python #type (type) and how to check type (type) for super beginners of Python
How to convert Python # type for Python super beginners: str edition
How to convert Python # type for Python super beginners: int, float edition
Read Python # .txt file for super beginners in Python with working .py
Python #Function 1 for Python Super Beginners
Python #Function 2 for super beginners of Python
[Python #len function for super beginners of Python] (https://qiita.com/Macchino5/items/a64347f9e832406d3c24)
Recommended Posts