We are proceeding with Python learning according to Learning Roadmap for Python Beginners on Tommy's blog. This time, refer to [Python] Summary of how to use string sequences. It deals with the concept of sequences and how to use strings.
--Those who are studying on Tomi-san's blog --For those who want to get an overview of string sequences
Google Colaboratory
About Python sequences What is a sequence? ** A warehouse (aggregate) that stores variables **
What is a string sequence?
x = "string"
In the case of, "x is a variable", which means that the character string is stored in x.
Slice ← ** Extract the stored character element **
x = "12345Python"
x [0]
Slice the 0th of x
1 ← 0 is on the far left (Python is customary)
x [-11]
Slice the 11th from the right
1 ← 11th (that is, 0th) 1 counting from the right
x [0: 3]
Slice from 0 to 3
123 ← I got from 0 to 3
x [:]
All slices
12345Python ← I brought all the strings
x[0:12:2]
'135yhn' ← Slice from 0 to 12 at 2 intervals
The method of acquiring the character string differs depending on the format in [], so use it properly according to the purpose.
[Python] Summary of how to use string sequences
Recommended Posts