Python - check if string doesn't contain character

0 points
Created by:

In this article, we would like to show you how to check if string doesn't contain character in Python.

Quick solution:

text = "ABC"
print("D" not in text)  # True


Practical example

In this example, we check if D character is NOT present in the text string using in keyword.

text = "ABC"
if "D" not in text:
    print("The 'D' character isn't present in the", text)


The 'D' character isn't present in the ABC

Alternative titles

  1. Python - check if character is not present in string
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Python - string (popular problems)

Python - check if string doesn't contain character
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂