- Introduction to PyCharm
- What is an IDE?
- Importance of IDE
- Introduction to Python
- Python Development Environment
- Tools and Features of PyCharm
- Writing Code in PyCharm
- Running Code in PyCharm
- Debugging in PyCharm
- Testing in PyCharm
Contributed by: Mr. Somak Sengupta
LinkedIn Profile: https://www.linkedin.com/in/somak-sengupta/
Introduction to PyCharm
PyCharm is one of the most famous Integrated Development Environment (IDE) for Python, developed by a Czech organization called JetBrains. The integrated environment comes with the platform for Code Analysis, Graphical Debugger, Unit Tester and Version Control Systems, etc. It also supports web development with the Django framework.
What is an IDE?
An IDE is a software application/platform that provides an integrated environment to the programmers to develop, build, debug, package & deploy codes in multiple languages. Some of the famous IDE’s are NetBeans, Eclipse (extremely popular for Java), etc. IDEs also provide interactive GUI tools to develop front-end applications which could take longer to develop if done manually (by coding).
Importance of IDE
Few of the major benefits of an IDE are-
- An Interactive interface that helps the programmers by detecting syntactic or semantic errors while developing. Contrary to non-IDE where errors are found during the build. This eventually reduces the debugging time.
- Reduces complexity related to the configuration of the environment.
- Inbuilt version controlling mechanism.
- IDEs provide the provision of Visual programming that allows programmers to create flow-charts, block diagrams etc.
All these collectively maximize the productivity of programmers.
Introduction to Python
Python is an open-source, interpreted, general-purpose programming language. It uses the concepts of object-oriented programming that help programmers develop large applications by splitting it into smaller building blocks. It was first developed by Guido van Rossum in 1990. One of the primary reasons Python became famous is due to the availability of numerous modules (a.k.a. standard library) that are publicly available for commercial use. Also, learning python is relatively easier than other programming languages due to its lesser complexity in syntaxes and semantics. Nowadays, popular uses of python are in Data Science, Machine Learning, Web Development, etc. Guess What! The world’s first Black Hole image was also developed using Python – it’s that powerful.
Python Development Environments
Python codes can be developed in different environments. There are a lot of open-source platforms available to write codes in python. Basic programming can also be done in Python prompt. Some advanced and user-friendly interactive platforms like Spyder and Jupyter are also available. However, in order to develop and deploy large python applications, PyCharm would be one of the best IDEs.
Tools & Features of PyCharm
1. Project Window
Provides complete navigation of project-related objects (like python script files/data files, etc) including the libraries available in the site-packages repository.
2. Structure Window
It provides the list of variables and datasets created in the selected python file.
3. Code Editor Window
A window where you write your python codes is known as Code Editor Window.
4. Terminal & Run
The console window is where programmers can write a piece of code and see the result after execution.
5. Event Log
The log is where programmers can see the events related to the environment. This includes the module installation, upgrades, etc.
Writing code in PyCharm
Writing code in an IDE is one of the easiest things in the world. However, you need to know a few basic configurations and settings, to begin with. Here is a quick snapshot of how you can do it in PyCharm:
1. Go to Menu bar – File > New Project
2. Create Project
This dialogue/input box allows you to give the name of the project, select the python environment you want to use (you could use Virtualenv which is provided by PyCharm or Conda environment which is provided by Anaconda), set the location of your project (recommended to use the one which is by default – to avoid any complications).
3. And you are ready to go!
4. Create a new python file in your project. Let’s say we name it as ‘my_first_python_code.py’
5. Once we create the file, the code editor opens and we write our python code in it.
Running Code in PyCharm
Once we write our code in the code editor, we want to execute it. There are multiple ways of doing so-
- By using hot keys / shortcut keys :
-Alt+Shift+E 🡪 this executes the highlighted piece of code in the editor.
-Shift+F10 🡪 this executes the entire code or the entire script.
2. Or simply use the following tool to execute the complete code. The difference between the highlighted Run (Shift+F10) and the second Run (Alt+Shift+F10) is that the first one only executes the current Python script (or file) while the second one executes all the python files or scripts in the projects. Note that in that case, the sequence has to be defined or maintained by the programmer.
Debugging in PyCharm
An IDE debugger lets you change the values of variables at run-time. It lets you conditionally break execution at any point in code, based on a condition.
1. Go to Menu > Debug or use hot keys Shift+F9 to start the debugger.
2. This is how a debugger console looks like for a code which has no errors:
3. This is how a debugger console looks like when a code has errors:
Testing in PyCharm
To test code in Python, PyCharm provides an inbuilt Unit Tester. Here is how we can test our first function using the Test feature provided in PyCharm.
1. Right click on the function(return true if an integer given is Even) you want to perform unit testing, select Go To > Test
2. Select Create New Test
3. Hit the Ok button
4. Run the Unittest code as follows. This code will check if the return type of the is_even function is true and accordingly mark the test case as pass or fail.
In conclusion, this is how you can get started with Pycharm. Found this tutorial helpful? Upskill with Great Learning’s PGP- Data Science and Analytics course today and learn more such content!2