1
3

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での文字列から文字を検索し何番目の文字かを取得する処理

Posted at

Python3で、文字列から文字を検索し、何番目の文字かを取得する処理のコードです

# 文字列を入力する
input_line1 = input()
# 検索したい文字を入力する
input_line2 = input()
# 検索したい文字が0番から数えて何番目か取得する
num = input_line1.find(input_line2)
# 検索したい文字が何番目か表示する(0番目から始まっているので1を足す)
print(num+1)

文字列でも配列でも0番目から始まることに注意して1番最後の行に1を足します。

1
3
1

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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?