0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python3 [::1]や[::2]を並べた アウトプット

Posted at

まんまです
学習していてこの辺りややこしいのでリストアップしてみました

w="aiueo"
print(w)
# aiueo

# 0番目から0文字飛ばしで返す
print(w[::1])
# aiueo

# 0番目から1文字飛ばしで返す
print(w[::2])
# auo

# 0番目から2文字飛ばしで返す
print(w[::3])
# ae

# 1番目から1文字飛ばしで返す
print(w[1::2])
# ie

# 1番目から1文字飛ばしで返す
print(w[int(True)::2])
# ie

# 0番目から1文字飛ばしで返す
print(w[int(False)::2])
# auo

# 1番目から1文字飛ばしで返す
print(w[(True)::2])
# ie

# 0番目から1文字飛ばしで返す
print(w[(False)::2])
# auo



# 下記 おまけ
# 単体で使うと真偽
print(True)
# True

# 単体で使うと真偽
print(False)
# False

# intと組み合わせるとTrueはint:1を返す
print(True+0)
# 1

# intと組み合わせるとFalseはint:0を返す
print(False+0)
# 0
0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?