LoginSignup
0
0

More than 1 year has passed since last update.

はじめに

移植やってます

None (Python)

a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

print(a[2:])
print(a[2:-1])
print(a[2:None])

# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8]   
# [2, 3, 4, 5, 6, 7, 8, 9]

へぇー、:Noneだと末尾まで行くんだ。

nil (Ruby)

a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

p a[2..]
p a[2...]
p a[2..-1]
p a[2...-1]
p a[2..nil]
p a[2...nil]

# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8]
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8, 9]

-1とは異なり、..nil...nilも同じ動作となります。

メモ

  • Python の None を学習した
  • 道のりは遠そう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0