René's URL Explorer Experiment


Title: Python's assert: Debug and Test Your Code Like a Pro – Real Python

Open Graph Title: Python's assert: Debug and Test Your Code Like a Pro – Real Python

Description: In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development. You'll learn how assertions might be disabled in production code, so you shouldn't use them to validate data. You'll also learn about a few common pitfalls of assertions in Python.

Open Graph Description: In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development. You'll learn how assertions might be disabled in production code, so you shouldn't use them to validate data. You'll also learn about a few common pitfalls of assertions in Python.

Mail addresses
?subject=Python article for you&body=Python's assert: Debug and Test Your Code Like a Pro on Real Python https://realpython.com/python-assert-statement/

Opengraph URL: https://realpython.com/python-assert-statement/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Python's assert: Debug and Test Your Code Like a Pro",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/Pythons-assert-Statement_Watermarked.b22344aad0fa.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/python-assert-statement/",
    "lastReviewed": "2025-01-12",
    "author": {
      "@type": "Person",
      "name": "Leodanis Pozo Ramos",
      "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
      "url": "https://realpython.com/team/lpozoramos/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Brenda Weleschuk",
        "image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
        "url": "https://realpython.com/team/bweleschuk/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Bartosz Zaczy\u0144ski",
        "image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
        "url": "https://realpython.com/team/bzaczynski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Dan Bader",
        "image": "https://realpython.com/cdn-cgi/image/width=1000,height=1000,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/daniel-square.d58bf4388750.jpg",
        "url": "https://realpython.com/team/dbader/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Geir Arne Hjelle",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
        "url": "https://realpython.com/team/gahjelle/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Kate Finegan",
        "image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/VZxEtUor_400x400.7169c68e3950.jpg",
        "url": "https://realpython.com/team/kfinegan/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Martin Breuss",
        "image": "https://realpython.com/cdn-cgi/image/width=456,height=456,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/martin_breuss_python_square.efb2b07faf9f.jpg",
        "url": "https://realpython.com/team/mbreuss/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2025-01-12T14:00:00+00:00",
  "dateModified": "2025-01-12T14:09:23.526932+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Leodanis Pozo Ramos",
    "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
    "url": "https://realpython.com/team/lpozoramos/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development. You'll learn how assertions might be disabled in production code, so you shouldn't use them to validate data. You'll also learn about a few common pitfalls of assertions in Python.",
  "hasPart": {
    "@type": "FAQPage",
    "mainEntity": [
      {
        "@type": "Question",
        "name": "What is assert in Python?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "

In Python, assert is a statement you can use to set sanity checks in your code, allowing you to test conditions that should remain true during development.

" } }, { "@type": "Question", "name": "What does assert do?", "acceptedAnswer": { "@type": "Answer", "text": "

The assert statement checks if a given condition is true. If it’s false, the statement raises an AssertionError and halts program execution.

" } }, { "@type": "Question", "name": "Should you use asserts in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

Yes, you should use assert statements for debugging, testing, and documenting code during development, but avoid using them for data validation or error handling in production.

" } }, { "@type": "Question", "name": "What is raise and assert in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

In Python, you use raise to trigger exceptions explicitly, while you use assert to check for conditions. If an assert condition is false, Python will automatically raise an AssertionError.

" } } ] } }

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/Pythons-assert-Statement_Watermarked.b22344aad0fa.jpg
og:imagehttps://files.realpython.com/media/Pythons-assert-Statement_Watermarked.b22344aad0fa.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/python-assert-statement/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/python-assert-statement/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fpython-assert-statement%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/python-assert-statement/#toc
Getting to Know Assertions in Pythonhttps://realpython.com/python-assert-statement/#getting-to-know-assertions-in-python
What Are Assertions?https://realpython.com/python-assert-statement/#what-are-assertions
What Are Assertions Good For?https://realpython.com/python-assert-statement/#what-are-assertions-good-for
When Not to Use Assertions?https://realpython.com/python-assert-statement/#when-not-to-use-assertions
Understanding Python’s assert Statementshttps://realpython.com/python-assert-statement/#understanding-pythons-assert-statements
The Syntax of the assert Statementhttps://realpython.com/python-assert-statement/#the-syntax-of-the-assert-statement
The AssertionError Exceptionhttps://realpython.com/python-assert-statement/#the-assertionerror-exception
Exploring Common Assertion Formatshttps://realpython.com/python-assert-statement/#exploring-common-assertion-formats
Documenting Your Code With Assertionshttps://realpython.com/python-assert-statement/#documenting-your-code-with-assertions
Debugging Your Code With Assertionshttps://realpython.com/python-assert-statement/#debugging-your-code-with-assertions
An Example of Debugging With Assertionshttps://realpython.com/python-assert-statement/#an-example-of-debugging-with-assertions
A Few Considerations on Debugging With Assertionshttps://realpython.com/python-assert-statement/#a-few-considerations-on-debugging-with-assertions
Disabling Assertions in Production for Performancehttps://realpython.com/python-assert-statement/#disabling-assertions-in-production-for-performance
Understanding the __debug__ Built-in Constanthttps://realpython.com/python-assert-statement/#understanding-the-__debug__-built-in-constant
Running Python With the -O or -OO Optionshttps://realpython.com/python-assert-statement/#running-python-with-the-o-or-oo-options
Setting the PYTHONOPTIMIZE Environment Variablehttps://realpython.com/python-assert-statement/#setting-the-pythonoptimize-environment-variable
Running Python in Optimized Modehttps://realpython.com/python-assert-statement/#running-python-in-optimized-mode
Testing Your Code With Assertionshttps://realpython.com/python-assert-statement/#testing-your-code-with-assertions
Understanding Common Pitfalls of asserthttps://realpython.com/python-assert-statement/#understanding-common-pitfalls-of-assert
Using assert for Data Processing and Validationhttps://realpython.com/python-assert-statement/#using-assert-for-data-processing-and-validation
Handling Errors With asserthttps://realpython.com/python-assert-statement/#handling-errors-with-assert
Running assert on Expressions With Side Effectshttps://realpython.com/python-assert-statement/#running-assert-on-expressions-with-side-effects
Impacting Performance With asserthttps://realpython.com/python-assert-statement/#impacting-performance-with-assert
Having assert Statements Enabled by Defaulthttps://realpython.com/python-assert-statement/#having-assert-statements-enabled-by-default
Conclusionhttps://realpython.com/python-assert-statement/#conclusion
Frequently Asked Questionshttps://realpython.com/python-assert-statement/#frequently-asked-questions
https://realpython.com/feedback/survey/article/python-assert-statement/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/python-assert-statement/disliked/?from=article-sidebar
Using Python's assert to Debug and Test Your Codehttps://realpython.com/courses/python-assert-statement/
Leodanis Pozo Ramoshttps://realpython.com/python-assert-statement/#author
https://realpython.com/python-assert-statement/#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
best-practiceshttps://realpython.com/tutorials/best-practices/
pythonhttps://realpython.com/tutorials/python/
Getting to Know Assertions in Pythonhttps://realpython.com/python-assert-statement/#getting-to-know-assertions-in-python
What Are Assertions?https://realpython.com/python-assert-statement/#what-are-assertions
What Are Assertions Good For?https://realpython.com/python-assert-statement/#what-are-assertions-good-for
When Not to Use Assertions?https://realpython.com/python-assert-statement/#when-not-to-use-assertions
Understanding Python’s assert Statementshttps://realpython.com/python-assert-statement/#understanding-pythons-assert-statements
The Syntax of the assert Statementhttps://realpython.com/python-assert-statement/#the-syntax-of-the-assert-statement
The AssertionError Exceptionhttps://realpython.com/python-assert-statement/#the-assertionerror-exception
Exploring Common Assertion Formatshttps://realpython.com/python-assert-statement/#exploring-common-assertion-formats
Documenting Your Code With Assertionshttps://realpython.com/python-assert-statement/#documenting-your-code-with-assertions
Debugging Your Code With Assertionshttps://realpython.com/python-assert-statement/#debugging-your-code-with-assertions
An Example of Debugging With Assertionshttps://realpython.com/python-assert-statement/#an-example-of-debugging-with-assertions
A Few Considerations on Debugging With Assertionshttps://realpython.com/python-assert-statement/#a-few-considerations-on-debugging-with-assertions
Disabling Assertions in Production for Performancehttps://realpython.com/python-assert-statement/#disabling-assertions-in-production-for-performance
Understanding the __debug__ Built-in Constanthttps://realpython.com/python-assert-statement/#understanding-the-__debug__-built-in-constant
Running Python With the -O or -OO Optionshttps://realpython.com/python-assert-statement/#running-python-with-the-o-or-oo-options
Setting the PYTHONOPTIMIZE Environment Variablehttps://realpython.com/python-assert-statement/#setting-the-pythonoptimize-environment-variable
Running Python in Optimized Modehttps://realpython.com/python-assert-statement/#running-python-in-optimized-mode
Testing Your Code With Assertionshttps://realpython.com/python-assert-statement/#testing-your-code-with-assertions
Understanding Common Pitfalls of asserthttps://realpython.com/python-assert-statement/#understanding-common-pitfalls-of-assert
Using assert for Data Processing and Validationhttps://realpython.com/python-assert-statement/#using-assert-for-data-processing-and-validation
Handling Errors With asserthttps://realpython.com/python-assert-statement/#handling-errors-with-assert
Running assert on Expressions With Side Effectshttps://realpython.com/python-assert-statement/#running-assert-on-expressions-with-side-effects
Impacting Performance With asserthttps://realpython.com/python-assert-statement/#impacting-performance-with-assert
Having assert Statements Enabled by Defaulthttps://realpython.com/python-assert-statement/#having-assert-statements-enabled-by-default
Conclusionhttps://realpython.com/python-assert-statement/#conclusion
Frequently Asked Questionshttps://realpython.com/python-assert-statement/#frequently-asked-questions
Remove adshttps://realpython.com/account/join/
Using Python's assert to Debug and Test Your Codehttps://realpython.com/courses/python-assert-statement/
expressions and operatorshttps://realpython.com/python-operators-expressions/
functionshttps://realpython.com/defining-your-own-python-function/
conditional statementshttps://realpython.com/python-conditional-statements/
exceptionshttps://realpython.com/python-exceptions/
documentinghttps://realpython.com/documenting-python-code/
debugginghttps://realpython.com/python-debugging-pdb/
testinghttps://realpython.com/python-testing/
Get a sample chapter from Python Tricks: The Bookhttps://realpython.com/bonus/python-tricks-sample-pdf/
https://realpython.com/python-assert-statement/#getting-to-know-assertions-in-python
assertionshttps://en.wikipedia.org/wiki/Assertion_(software_development)
Chttps://realpython.com/c-for-python-programmers/
Javahttps://realpython.com/java-vs-python/
documentinghttps://realpython.com/documenting-python-code/
debugginghttps://realpython.com/python-debugging-pdb/
testinghttps://realpython.com/python-testing/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#what-are-assertions
statementshttps://realpython.com/ref/glossary/statement/
invariantshttps://en.wikipedia.org/wiki/Invariant_(mathematics)#Invariants_in_computer_science
preconditionshttps://en.wikipedia.org/wiki/Precondition
postconditionshttps://en.wikipedia.org/wiki/Postcondition
Nonehttps://realpython.com/null-in-python/
stringhttps://realpython.com/python-strings/
https://realpython.com/python-assert-statement/#what-are-assertions-good-for
return valueshttps://realpython.com/python-return-statement/
commentshttps://realpython.com/python-comments-guide/
docstringshttps://realpython.com/documenting-python-code/#documenting-your-python-code-base-using-docstrings
test caseshttps://en.wikipedia.org/wiki/Test_case
https://realpython.com/python-assert-statement/#when-not-to-use-assertions
Understanding Common Pitfalls of asserthttps://realpython.com/python-assert-statement/#understanding-common-pitfalls-of-assert
try … excepthttps://realpython.com/python-exceptions/#the-try-and-except-block-handling-exceptions
https://realpython.com/python-assert-statement/#understanding-pythons-assert-statements
keywordhttps://realpython.com/python-keywords/
functionhttps://realpython.com/defining-your-own-python-function/
asserthttps://docs.python.org/3/reference/simple_stmts.html#the-assert-statement
AssertionErrorhttps://docs.python.org/3/library/exceptions.html#AssertionError
https://realpython.com/python-assert-statement/#the-syntax-of-the-assert-statement
simple statementhttps://docs.python.org/3/reference/simple_stmts.html#simple-statements
expressionhttps://realpython.com/python-operators-expressions/
truthinesshttps://realpython.com/python-boolean/#python-boolean-testing
tracebackhttps://realpython.com/python-traceback/
SyntaxWarninghttps://docs.python.org/3/library/exceptions.html#SyntaxWarning
tupleshttps://realpython.com/python-tuple/
explicit line joininghttps://docs.python.org/3/reference/lexical_analysis.html#explicit-line-joining
physical lineshttps://docs.python.org/3/reference/lexical_analysis.html#physical-lines
logical linehttps://docs.python.org/3/reference/lexical_analysis.html#logical-lines
line lengthhttps://realpython.com/python-pep8/#maximum-line-length-and-line-breaking
PEP 679https://www.python.org/dev/peps/pep-0679/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#the-assertionerror-exception
AssertionErrorhttps://docs.python.org/3/library/exceptions.html#AssertionError
Exceptionhttps://docs.python.org/3/library/exceptions.html#Exception
https://realpython.com/python-assert-statement/#exploring-common-assertion-formats
comparison operatorshttps://realpython.com/python-operators-expressions/#comparison-operators
Booleanhttps://realpython.com/python-boolean/
membershiphttps://docs.python.org/3/reference/expressions.html#membership-test-operations
listhttps://realpython.com/python-lists-tuples/
sethttps://realpython.com/python-sets/
dictionaryhttps://realpython.com/python-dicts/
inhttps://realpython.com/python-in-operator/
not inhttps://realpython.com/python-in-operator/#pythons-not-in-operator
identityhttps://realpython.com/python-is-identity-vs-equality/
ishttps://docs.python.org/3/reference/expressions.html#is
is nothttps://docs.python.org/3/reference/expressions.html#is-not
isinstance()https://realpython.com/what-does-isinstance-do-in-python/
all()https://realpython.com/python-all/
any()https://realpython.com/any-python/
Boolean-valued functionshttps://en.wikipedia.org/wiki/Boolean-valued_function
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#documenting-your-code-with-assertions
docstringhttps://realpython.com/how-to-write-docstrings-in-python/
https://realpython.com/python-assert-statement/#debugging-your-code-with-assertions
https://realpython.com/python-assert-statement/#an-example-of-debugging-with-assertions
.__init__()https://docs.python.org/3/reference/datamodel.html#object.__init__
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#a-few-considerations-on-debugging-with-assertions
https://realpython.com/python-assert-statement/#disabling-assertions-in-production-for-performance
https://realpython.com/python-assert-statement/#understanding-the-__debug__-built-in-constant
__debug__https://docs.python.org/3/library/constants.html#debug__
nothttps://realpython.com/python-not-operator/
–Ohttps://docs.python.org/3/using/cmdline.html#cmdoption-O
-OOhttps://docs.python.org/3/using/cmdline.html#cmdoption-OO
PYTHONOPTIMIZEhttps://docs.python.org/3/using/cmdline.html#envvar-PYTHONOPTIMIZE
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#running-python-with-the-o-or-oo-options
bytecodehttps://docs.python.org/3/glossary.html#term-bytecode
@propertyhttps://realpython.com/python-property/
running the scripthttps://realpython.com/run-python-scripts/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#setting-the-pythonoptimize-environment-variable
Windowshttps://realpython.com/python-assert-statement/#windows-1
Linux + macOShttps://realpython.com/python-assert-statement/#linux-macos-1
Windowshttps://realpython.com/python-assert-statement/#windows-2
Linux + macOShttps://realpython.com/python-assert-statement/#linux-macos-2
https://realpython.com/python-assert-statement/#running-python-in-optimized-mode
Python 3.10https://realpython.com/python310-new-features/
PEP 488https://www.python.org/dev/peps/pep-0488/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#testing-your-code-with-assertions
pytesthttps://realpython.com/pytest-python-testing/
APIhttps://en.wikipedia.org/wiki/API
unittesthttps://docs.python.org/3/library/unittest.html
.assert*() methodshttps://docs.python.org/3/library/unittest.html#assert-methods
Windowshttps://realpython.com/python-assert-statement/#windows-3
Linux + macOShttps://realpython.com/python-assert-statement/#linux-macos-3
pytest.raises()https://docs.pytest.org/en/latest/how-to/assert.html#assertions-about-expected-exceptions
expected to failhttps://realpython.com/python-testing/#handling-expected-failures
https://realpython.com/python-assert-statement/#understanding-common-pitfalls-of-assert
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#using-assert-for-data-processing-and-validation
dictionaryhttps://realpython.com/python-dicts/
tracebackhttps://realpython.com/python-traceback/
https://realpython.com/python-assert-statement/#handling-errors-with-assert
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#running-assert-on-expressions-with-side-effects
side effecthttps://en.wikipedia.org/wiki/Side_effect_(computer_science)
statehttps://en.wikipedia.org/wiki/State_(computer_science)
scopehttps://realpython.com/python-scope-legb-rule/
global variablehttps://realpython.com/python-use-global-variable-in-function/
pure functionshttps://en.wikipedia.org/wiki/Pure_function
namespaceshttps://realpython.com/python-namespaces-scope/
https://realpython.com/python-assert-statement/#impacting-performance-with-assert
classeshttps://realpython.com/python-classes/
https://realpython.com/python-assert-statement/#having-assert-statements-enabled-by-default
https://realpython.com/python-assert-statement/#conclusion
sanity checkshttps://en.wikipedia.org/wiki/Sanity_check
Get a sample chapter from Python Tricks: The Bookhttps://realpython.com/bonus/python-tricks-sample-pdf/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-assert-statement/#frequently-asked-questions
https://realpython.com/feedback/survey/article/python-assert-statement/liked/?from=article-footer
https://realpython.com/feedback/survey/article/python-assert-statement/disliked/?from=article-footer
Using Python's assert to Debug and Test Your Codehttps://realpython.com/courses/python-assert-statement/
https://realpython.com/team/lpozoramos/
» More about Leodanishttps://realpython.com/team/lpozoramos/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bweleschuk/
Brendahttps://realpython.com/team/bweleschuk/
https://realpython.com/team/bzaczynski/
Bartoszhttps://realpython.com/team/bzaczynski/
https://realpython.com/team/dbader/
Danhttps://realpython.com/team/dbader/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/kfinegan/
Katehttps://realpython.com/team/kfinegan/
https://realpython.com/team/mbreuss/
Martinhttps://realpython.com/team/mbreuss/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-assert-statement
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-assert-statement
https://realpython.com/feedback/survey/article/python-assert-statement/liked/?from=article-comments
https://realpython.com/feedback/survey/article/python-assert-statement/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fpython-assert-statement%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20Python%27s%20assert%3A%20Debug%20and%20Test%20Your%20Code%20Like%20a%20Pro&url=https%3A%2F%2Frealpython.com%2Fpython-assert-statement%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20Python%27s%20assert%3A%20Debug%20and%20Test%20Your%20Code%20Like%20a%20Pro%20https%3A%2F%2Frealpython.com%2Fpython-assert-statement%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fpython-assert-statement%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
best-practiceshttps://realpython.com/tutorials/best-practices/
pythonhttps://realpython.com/tutorials/python/
Using Python's assert to Debug and Test Your Codehttps://realpython.com/courses/python-assert-statement/
Effective Python Testing With pytesthttps://realpython.com/pytest-python-testing/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-assert-statement
Python Exceptions: An Introductionhttps://realpython.com/python-exceptions/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-assert-statement
Build a Hash Table in Python With TDDhttps://realpython.com/python-hash-table/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-assert-statement
Python's unittest: Writing Unit Tests for Your Codehttps://realpython.com/python-unittest/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-assert-statement
Python's raise: Effectively Raising Exceptions in Your Codehttps://realpython.com/python-raise-exception/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-assert-statement
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-assert-statement%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-assert-statement%2F
Sign-Inhttps://realpython.com/account/login/?next=/python-assert-statement/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.