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?

「文字列”p”が含まれない」の表現方法

Posted at

1. not in 文字列

可読性が高い

domain = "[example.com](http://example.com/)"
if "@" not in domain:
print("@は含まれていません")

2. find() == -1

対象の文字が見つからない場合、-1を返す

domain = "[example.com](http://example.com/)"
if domain.find("@") == -1:
print("@は含まれていません")

3. count()

出現回数をカウントし、0なら含まれていないと同値

domain = "[example.com](http://example.com/)"
if domain.count("@") == 0:
print("@は含まれていません")
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?