Python #index for super beginners, slices

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.

index

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.

slice

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

A little application

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

table of contents

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

Python #index for super beginners, slices
Python #function 2 for super beginners
Python for super beginners Python #functions 1
Python #list for super beginners
Python for super beginners Python # dictionary type 1 for super beginners
Python #len function for super beginners
Python #Hello World for super beginners
Python for super beginners Python # dictionary type 2 for super beginners
Let's put together Python for super beginners
python textbook for beginners
OpenCV for Python beginners
Python for super beginners Python for super beginners # Easy to get angry
Easy understanding of Python for & arrays (for super beginners)
About Python external module import <For super beginners>
Learning flow for Python beginners
Python3 environment construction (for beginners)
Basic Python grammar for beginners
100 Pandas knocks for Python beginners
~ Tips for beginners to Python ③ ~
How to convert Python # type for Python super beginners: str
Python # How to check type and type for super beginners
<For beginners> python library <For machine learning>
How to convert Python # type for Python super beginners: int, float
Beginners use Python for web scraping (1)
[Python] Reasons for overriding using super ()
Run unittests in Python (for beginners)
Beginners use Python for web scraping (4) ―― 1
[Kaggle for super beginners] Titanic (Logistic regression)
[Python] Minutes of study meeting for beginners (7/15)
[Python] Read images with OpenCV (for beginners)
WebApi creation with Python (CRUD creation) For beginners
Atcoder standard input set for beginners (python)
[For beginners] Try web scraping with Python
A textbook for beginners made by Python beginners
2016-10-30 else for Python3> for:
python [for myself]
Beginners practice Python
Python beginner's note
Memo # 4 for Python beginners to read "Detailed Python Grammar"
The fastest way for beginners to master Python
Causal reasoning and causal search with Python (for beginners)
For new students (Recommended efforts for Python beginners Part 1)
Memo # 3 for Python beginners to read "Detailed Python Grammar"
Memo # 1 for Python beginners to read "Detailed Python Grammar"
~ Tips for Python beginners from Pythonista with love ① ~
Try to calculate RPN in Python (for beginners)
Memo # 2 for Python beginners to read "Detailed Python Grammar"
Memo # 7 for Python beginners to read "Detailed Python Grammar"
Introduction to Programming (Python) TA Tendency for beginners
Installing TensorFlow on Windows Easy for Python beginners
Memo # 6 for Python beginners to read "Detailed Python Grammar"
How to make Python faster for beginners [numpy]
~ Tips for Python beginners from Pythonista with love ② ~
Memo # 5 for Python beginners to read "Detailed Python Grammar"
[Introduction for beginners] Working with MySQL in Python
Basic story of inheritance in Python (for beginners)
Rock-paper-scissors poi in Python for beginners (answers and explanations)
About Python for loops
Python Beginner's Guide (Functions)
[For beginners] How to use say command in python!
Beginners can use Python for web scraping (1) Improved version