Last active
September 9, 2019 00:26
-
-
Save mizushou/3e24a083b8a03bcde5a836895e844b18 to your computer and use it in GitHub Desktop.
sliceサンプル集
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Advanced slicing | |
""" | |
# 応用的な使い方1 | |
# third parameterはstep size.この例ではstep size = 2 | |
s = 'Python is Fun!' | |
s[1:12:2] | |
# ---> 'yhni u' | |
# 応用的な使い方2 | |
# we're asking for the full string s (from index 0 through 13), with a step size of 2 | |
s[::2] | |
# ---> 'Pto sFn' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Slicing | |
""" | |
# 基本的な使い方1 | |
'eric'[1:3] | |
# ---> 'ri' | |
# 基本的な使い方2 | |
# If no value after :, end at length | |
'eric'[1:] | |
# ---> 'ric' | |
# 基本的な使い方3 | |
# If no value before :, start at 0 | |
'eric'[:3] | |
# ---> 'eri' | |
# 基本的な使い方4 | |
# If just:, make a copy of entire sequence | |
'eric'[:] | |
# ---> 'eric' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment