Skip to content

Instantly share code, notes, and snippets.

@mizushou
Last active September 9, 2019 00:26
Show Gist options
  • Save mizushou/3e24a083b8a03bcde5a836895e844b18 to your computer and use it in GitHub Desktop.
Save mizushou/3e24a083b8a03bcde5a836895e844b18 to your computer and use it in GitHub Desktop.
sliceサンプル集
"""
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'
"""
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