How to Perform Debugging in Python PyCharm?
Last Updated :
20 Mar, 2024
Debugging is like finding and fixing mistakes in your computer code. PyCharm is a tool that helps with this, especially for Python code. It has special tools to make debugging easier. Whether you're new to programming or have been doing it for a while, getting good at debugging in PyCharm can make you a better coder. In this article, we will see how to Perform debugging in PyCharm.
Perform Debugging in Python PyCharm
When we run the Python code it shows two modes.
Now in this article let's focus on debugging the Python script file using PyCharm. While operating debugging there are some steps to be followed.
Step 1: Access Project Files in PyCharm
Open the project file and click the left button of the mouse. Then the following display will appear.

Step 2: Start Debugging in PyCharm
After clicking on a option Debug or press 'Shift+F9' , The Window firewall displays a pop-up message for debugging the project file for line by line compilation.

Step 3: Access Debugging Controls
After setting the permission then PyCharm starts debugging, the debugging executes till it reaches the break point, all the debugging controls will displayed on debug tool window. Lets take an example of a Python program in which we perform an operation of debugging in python.
Python3
import math
# Function to check if a number is prime
def is_prime(num):
if num <= 1:
return False
elif num <= 3:
return True
elif num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i <= math.isqrt(num):
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
# Take input from the user
user_input = int(input("Enter a number: "))
print("Checking if", user_input, "is prime...")
# Check if the input is prime
if is_prime(user_input):
print(user_input, "is a prime number.")
else:
print(user_input, "is not a prime number.")
-min-min.png)
Place a Breakpoints in the code by clicking on the number to suspend the program when Exception or its subclasses are thrown.

Step 4: Controls in PyCharm's Debug Tool Window
In the debug tool window, we will find various controls to help us navigate through our code while debugging. Now let us see some of the most commonly used tools.

- Step Over (F8): Executes the current line of code and moves to the next line. If the current line contains a function call, it will execute the entire function and pause on the next line after the function call.
- Step Into (F7): Moves the debugger into the function call, allowing you to step through the function's code line by line.
- Step Out (Shift+F8): Executes the remaining lines of the current function and returns to the function that is called.
- Resume Program (F9): Continues execution until the next breakpoint is encountered or if no break point was found it executes till the end of a program.
Step 5 : Inspect variable and Expression Evaluation in Debugging
We can inspect the values of variables in our code by hovering over them with our mouse or by using the "Variables" pane present in the debug tool window. Similarly we can also evaluate expressions and watch variables by typing them into the "Evaluate Expression" field in the debug tool window.
Step 6: Terminate Debugging
If any error was found simply edit the code in the editor window and PyCharm will automatically save the changes. After completing the debugging session terminate the session by clicking the "Stop" icon in debug tool window and or by pressing "Ctrl+F2".
Inline Debugging
Inline Debugging a technique where we can inspect the values of variables and expressions directly in our code. This is used for quick state of code at specific points during execution.
Inline DebuggingThe above indicated points are the inline debugging which shows expression directly in our code. By following Process we can performing the debugging in PyCharm and by debugging tools built into PyCharm, we can easily identify and fix issues in our code.
Similar Reads
Python Tutorial - Learn Python Programming Language Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It'sA high-level language, used in web development, data science, automation, AI and more.Known fo
10 min read
Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
11 min read
Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Python Introduction Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read