python string slice

Introduction

The reason for writing this article is that I often use slices for the first time in competition pros, and my mind is getting crowded, so I decided to summarize it easily. It's just a slice note.

Program code

A string of numbers. The reason I chose a number string is because I thought the output result would be easy to understand.


s = "12345"
print(s[-1])  #end
5 #Output result
print(s[:-1])  #Delete the end
1234
print(s[0])  #lead
1
print(s[0:])  #From beginning to end
12345
print(s[1:])  #From first to last
2345

start = "6" + s[1:]
print(start) #Remove the beginning and add 6 to the beginning
62345

end = s[:-1] + "6"
print(end) #Remove the end and add 6 to the end
12346

Recommended Posts

python string slice
Python string
Python slice
Python: String concatenation
Python string format
Python slice basics
Python2 string type
Python string format
Python # string type
Python string inversion
String manipulation in python
[Python] Multi-line string assignment
Python string manipulation master
[Python2] Date string-> UnixTime-> Date string
Random string generation (Python)
Python3> documentation string / docstring
Python string processing illustration
[python] Array slice operation
[python] Convert date to string
Python indentation and string format
Python
String object methods in Python
slice
Cut a part of the string using a Python slice
[Python] Use a string sequence
Python and ruby slice memo
Various Python built-in string operations
Slice error in python (´ ; ω ; `)
[Python 2/3] Parse the format string
About Python string comparison operators
String date manipulation in Python
Python f character (formatted string)
String format with Python% operator
String replacement with Python regular expression
Slice without using Python, colon (:). a.__getitem__ (slice (3,5)).
6 ways to string objects in Python
python string processing map and lambda
Python> What is an extended slice?
Create a random string in Python
kafka python
Conversion of string <-> date (date, datetime) in Python
Python Summary
Built-in python
Python comprehension
Python technique
Studying python
Python 2.7 Countdown
Python FlowFishMaster
Python service
python tips
String format
python function ①
Python basics
Python memo
ufo-> python (3)
Python comprehension
install python
Python Singleton
(Java, JavaScript, Python) Comparison of string processing
Python basics ④
Python Memorandum 2