Python ide for beginners

Python IDE: PyCharm Tutorial for Beginners

The PyCharm IDE is one of the most popular editors used by professional Python developers and programmers. But if you are a beginner, don’t worry, it can help you too! Find out how to create Python projects using PyCharm and what basic features can help you write code more efficiently.

The PyCharm IDE is one of the most popular editors used by professional Python developers and programmers. The vast number of PyCharm features doesn’t make this IDE difficult to use–just the opposite. Many of the features help make Pycharm a great Python IDE for beginners.

If you are just starting to learn Python, you should try out different Python IDEs to see if you prefer working with PyCharm or with another editor.

In my previous article, I showed you how to install the PyCharm IDE on Windows and Ubuntu. In this article, you’ll find out how to create a program and run it using PyCharm. You’ll also get to know some of the features that help beginners write code.

After the PyCharm IDE, we’ll move on to other popular Python IDEs and review them. Follow our blog or subscribe at the bottom to get the hang of other IDEs like Spyder, Jupyter, and more!

Читайте также:  Projects on c sharp

How to create and run Python scripts in PyCharm

To create a Python script right click on the project name node and choose from the pop-up menu New › Python File.

PyCharm

The New Python file window appears.Enter the name of the file in the Name field.

PyCharm

Click OK and you are ready to code in the PyCharm editor.

PyCharm

Copy this example code into the editor:

def hello(): print("Hello!") hello()

Save the file by clicking on the title tab,

PyCharm

then pressing Ctrl+S or by clicking File › Save All.

PyCharm

How to Run Python Code in PyCharm

We can run a project or a single file by selecting the project/file node and choosing from the menu Run › Run (the green Run button) or by using a keyboard combination Alt+Shift+F10.

PyCharm

Click the name of your script.

At the bottom of the editor the Output window with the result will be shown.

PyCharm

User Interface of the Editor

In almost all Python IDEs, the working area is divided into several parts that help make working with files and code more convenient. The screen below illustrates these different parts and what they are doing.

PyCharm

On the top is the main menu, which contains commands like open file, open project, create project or file, run, debug code, etc. Under the main menu is a toolbar with the same functionality, but it provides quick access to these functions. At the bottom is a status bar that displays messages about errors, warnings, and the status of a project. The central part of the screen consists of the editor where you read and write code. To the left, right, and bottom of the editor are tool windows. They allow for many different tasks, for example: see the node of the project and quickly open it, search in files, run options, change debugging settings, etc.

How to Customize the PyCharm Theme and Color Scheme

The PyCharm IDE allows you to customize many options. The first custom function is the theme of the IDE. You have a choice among different themes. To access the themes click on File › Settings.

PyCharm

The Settings window appears. From the left pane, expand the Editor and Color Scheme menus.

PyCharm

In the right pane select from the Scheme drop-down list one of the scheme names. For example it may be currently set to the Default scheme. Please note: the default color in PyCharm is Darcula and here, Default means your OS’s default theme.

PyCharm

Click the OK button.

PyCharm

If the Change PyCharm Theme window appears, click the Yes button. You will see a new theme like this below.

PyCharm

You can also change font colors in the scheme. You’ll find all the available options in the Settings window.

PyCharm Features with Shortcuts

Code Highlighting

The main feature that helps developers in writing code is highlighting. The editor highlights symbols and keywords in the code. It helps a developer to find these words in the script fast and it helps to notice errors. For example strings are green in color, integers are in blue, functions are in dark blue, etc. You can also change colors for groups of words in the settings of the IDE. Syntax highlighting improves the readability of the code.

PyCharm

If you click on the symbol or word, all occurences of this word or symbol will be highlighted.

PyCharm

PyCharm also helps you with errors. If you make a mistake in the code, this word will be indicated by red underlining. Hovering over this word with the mouse displays a tooltip with details.

PyCharm

Code Completion

Another very important feature, especially if you are just starting to learn Python, is code completion. While writing code you don’t always remember all the keywords in Python. If you start writing a word, the IDE gives you suggestions in a pop-up list, from which you can choose the appropriate word. It’s very convenient.

You can invoke code completion with the Ctrl+Space command.

If you write code without importing a required package, you’ll see this underlined in red. Select the word and press Alt+Enter or click the red bulb.

PyCharm

The IDE helps by suggesting that you import this package. Click on it and the line containing import will be inserted into the code. Now you can use the code with functions from the package math.

PyCharm

PyCharm also helps you remove unused imports if you remove code that depended on a package. If you see an orange bulb, expand it and choose the Optimize imports option.

PyCharm

You can do it also by pressing Ctrl+Alt+O or by choosing from the menu Code › Optimize imports.

Input Definition

The next helpful feature is the ability to see the definition of a function. If, for example, you type input, but forgot how many and which parameters this function takes, you can display the documentation about this function. Just select the word and choose from the menu View › Quick Definition.

PyCharm

You can also choose Quick Documentation.

PyCharm

Expression Type

Python doesn’t require declaration of data types for variables. However, during writing many lines of code, sometimes you need to find out what data type is assigned to a variable. In PyCharm it is easy. Select the variable and choose from the menu View › Expression type.

PyCharm

Of course you can also use the keyboard shortcut Ctrl+Alt+P. In a popup window you see the data type.

PyCharm

Code Folding

The next useful feature is hiding parts of code. If your code is long, it is very useful to hide sections of code to improve readability. You can select a block of code to hide and choose from the menu Code › Folding › Fold Selection.

PyCharm

The selected code will be folded.

PyCharm

If you click the plus symbol («+»), you expand the block of code.

PyCharm

Code Constructs with Surround Templates

PyCharm provides adding surrounding fragments of code with constructs based on the language of the source code like if. For example, you can write only the condition for an if statement and select it.

PyCharm

Then you can choose from the menu Code › Surround With or press Ctrl+Alt+T.

PyCharm

The list of statements appears.

PyCharm

If you choose if expr, your selected code will be inserted as the condition of an if expression.

PyCharm

Code Inspection

In PyCharm you can also easily navigate to the declaration of a variable, function, etc. Select the name of an object and press Ctrl+B. In the screen below we selected the a variable.

PyCharm

PyCharm allows for analysis of code by inspection. It detects compiling errors, unused code, memory leaks, and other problems. By default it analyses all open files and highlights all detected problems. Just select from the menu Code › Inspect Code.

PyCharm

The Specify Inspection Scope window appears, where you can choose to inspect all of a project or one file.

PyCharm

Click the OK button.

At the bottom of the IDE you see errors and warnings. In our script there are missing spaces around operators and whitespace before the ‘:’ character.

PyCharm

If there are not any errors or warnings, you see a message about it.

PyCharm

How to Install Packages in the PyCharm IDE

PyCharm is similar to other Python IDEs in that it allows you to install packages and modules. In PyCharm this is a very easy process. First choose from the menu File › Settings › Project: project name › Project Interpreter

You will see the Settings window:

PyCharm

Here is displayed a list of installed packages. To install a new package, click the plus icon, which is next to the names of the columns. The Available Packages window is displayed. Find the package and click the Install Package button at the bottom of this window.

PyCharm

You see the new package in the list.

PyCharm

Click the OK button.You are ready to use the package in your project! 🙂

Summary

This article is a short beginner overview of using the PyCharm IDE for growing your Python programming skills. I showed you how the PyCharm user interface works, how to run scripts, and what features can help you in writing code.

Please note, this editor contains many more features and tools, but I discussed only the most useful functions available in the Community version of the editor. If you haven’t used an IDE before, maybe PyCharm will turn out to be your favorite for writing Python scripts. Try it out and have fun!

Источник

Thonny

Main screenshot

Easy to get started. Thonny comes with Python 3.10 built in, so just one simple installer is needed and you’re ready to learn programming. (You can also use a separate Python installation, if necessary.) The initial user interface is stripped of all features that may distract beginners.

No-hassle variables. Once you’re done with hello-worlds, select View → Variables and see how your programs and shell commands affect Python variables.

Simple debugger. Just press Ctrl+F5 instead of F5 and you can run your programs step-by-step, no breakpoints needed. Press F6 for a big step and F7 for a small step. Steps follow program structure, not just code lines.

Step through expression evaluation. If you use small steps, then you can even see how Python evaluates your expressions. You can think of this light-blue box as a piece of paper where Python replaces subexpressions with their values, piece-by-piece.

Faithful representation of function calls. Stepping into a function call opens a new window with separate local variables table and code pointer. Good understanding of how function calls work is especially important for understanding recursion.

Highlights syntax errors. Unclosed quotes and parentheses are the most common beginners’ syntax errors. Thonny’s editor makes these easy to spot.

Explains scopes. Highlighting variable occurrences reminds you that the same name doesn’t always mean the same variable and helps spotting typos. Local variables are visually distinguished from globals.

Mode for explaining references. Variables are initially presented according to simplified model (name → value) but you can switch to more realistic model (name → address/id → value).

Code completion. Students can explore APIs with the help of code completion.

Beginner friendly system shell. Select Tools → Open system shell to install extra packages or learn handling Python on command line. PATH and conflicts with other Python interpreters are taken care of by Thonny.

Simple and clean pip GUI. Select Tools → Manage packages for even easier installation of 3rd party packages.

Demo

Credits

From 2014 to 2018 the main development of Thonny took place in Institute of Computer Science of University of Tartu, Estonia.

Since September 2018 development of Thonny is partially supported by Cybernetica AS.

Development of several features in Thonny 3.0 and 3.3 was proposed and supported by Raspberry Pi Foundation.

Instructions & downloads

Latest stable releases are linked in the download box at the top of this page. Older releases and prereleases can be found at https://github.com/thonny/thonny/releases

Plug-ins

These are some known Thonny plug-ins:

  • thonny-gitonic adds a command for opening gitonic
  • thonny-black-format (abandoned)
  • thonny-black-formatter adds a command for formatting current file with Black
  • thonny-ev3dev allows uploading code to EV3 (and much more)
  • thonny-error-explainer extends Assistant with new error checkers
  • thonny-lahendus allows loading exercises from lahendus.ut.ee and submitting solutions for automatic assessment.
  • thonny-edison allows uploading Python code to Edison educational robot
  • thonny-dracula adds Dracula syntax theme.
  • thonny-onedark adds One Dark syntax theme.
  • thonny-crosshair adds commands for invoking CrossHair analyzer.
  • thonny-icontract-hypothesis adds commands for invoking icontract-hypothesis analyzer.
  • thonny-py5mode adds py5 support for a Processing-like creative coding environment.
  • ThonnyFlake8 adds warnings from flake8.
  • thonny-autosave adds the option for auto-saving your script in every 10 seconds.

Contact & News

Papers

Источник

Оцените статью