Let's put together Python for super beginners https://qiita.com/kkhouse/items/675b846d0bcf41cd191f
Python beginners talk about how to remember this much https://qiita.com/kkhouse/items/74d7acb768e6542339ac
It is a continuation of this area. I haven't made it into a series, but I have a feeling that it will be a series. We have set a limit on the amount of time we can spend, so this time we will rush to summarize the list.
"1, 2, 3, 4 ...", "Hokkaido, Miyagi prefecture, Tokyo, Fukuoka prefecture ...", etc.
You can combine multiple elements. It is often more convenient for a program to store multiple elements together than to store them individually in variables.
It may be easier to understand if you understand that a box called a variable is packed with multiple elements.
As a usage
pre_name =["Hokkaido","Miyagi Prefecture","Tokyo","Fukuoka Prefecture"]
print(pre_name)
Then
["Hokkaido","Miyagi Prefecture","Tokyo","Fukuoka Prefecture"]
Is output.
demo_list = [element,element,element・・・]
demo_list = list(element,element,element・・・)
There are two ways. By the way,
pre_name =["Hokkaido","Miyagi Prefecture","Tokyo","Fukuoka Prefecture"]
If you want to add a new element "Osaka" to the list of, use the append () method.
pre_name =["Hokkaido","Miyagi Prefecture","Tokyo","Fukuoka Prefecture"]
pre_name.append("Osaka")
print(pre_name)
#["Hokkaido","Miyagi Prefecture","Tokyo","Fukuoka Prefecture","Osaka"]
A method is simply an additional operation. You can add operations to variables by selecting "Variable.Method".
pre_name.append("Osaka")
Is instructing to append (add) Osaka prefecture to the box (variable) called pre_name. This append is the method.
Besides
list = [1,2,3,4]
list.remove(3)
print(mylist)
#[1,2,4]
And so on, there is a remove method that you can use to remove an element from the list.
When I was a super beginner, when I understood the meaning of being able to perform additional operations with this ".method", I remember that the program became readable dramatically.
This means that if you suppress the concept from the very beginning, your ability to read the code in the future will become much stronger!
The list is basic but a little deep, so that's it for today.
See you tomorrow
Recommended Posts