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.
Last time, I learned about lists, but some of the tweets from beginners say, "If you just want to print a list with print
, you should just write the content as it is in text. "
Yes I thought so too.
So, this time, I would like to explain index
as a prior knowledge before doing this using that list.
index.py
japanese_syll=['Ah','I','U','e','O']
#Except for variables[ ]Show only and correspond below'index'I will write.
['Ah','I','U','e','O']
[ 0 1 2 3 4]
[ -5 -4 -3 -2 -1]
The index starts at 0
.
Minus starts with -1
from the end.
When you want to retrieve the string a
list.py
japanese_syll=['Ah','I','U','e','O']
print(japanese_syll[0])
#Ah
print(japanese_syll[-5])
#Ah
And it looks like this. So far we have explained the index, but slices have also appeared.
Slicing is an operation to extract some elements of the list as described above.
list.py
mmaker_list = ["peach", "princess", "kuppa", [1, 2, 3, 4, 5], "mario"]
list_x = mmaker_list[0]
print(list_x)
#Extracts the element with index number 0.
#peach
list_x = mmaker_list[1:3]
print(list_x)
#Extracts the elements before index numbers 1 to 3.
#['princess', 'kuppa']
list_x = mmaker_list[:2]
print(list_x)
#Extracts the elements before index number 2.
#['peach', 'princess']
list_x = mmaker_list[3][4]
print(list_x)
#To retrieve the elements of a multiple list, first index number 3 and
#Extract with index number 4 in the multiple list.
#5
You can rewrite the contents of the list.
list.py
mmaker_list = ["peach", "princess", "kuppa", [1, 2, 3, 4, 5], "mario"]
mmaker_list[2] = "ghost"
print(mmaker_list)
#['peach', 'princess', 'ghost', [1, 2, 3, 4, 5], 'mario']
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)
Python #list for super beginners of Python
Recommended Posts