Python Indentation & Basic Syntax & Comment Statemetns

In this tutorial, you will learn about Python statements, why indentation is important in the use of comments in programming.

Python Statement

Instructions that a Python interpreter can execute are called statements. For example, a = 1 is an assignment statement. if statement, for statement, while statement, etc. are other kinds of statements which will be discussed later.

Multi-line statement

In Python, the end of a statement is marked by a newline character. But we can make a statement extend over multiple lines with the line continuation character (\). For example:

a = 1 + 2 + 3 + \
    4 + 5 + 6 + \
    7 + 8 + 9

This is an explicit line continuation. In Python, line continuation is implied inside parentheses ( ), brackets [ ], and braces { }. For instance, we can implement the above multi-line statement as:

a = (1 + 2 + 3 +
    4 + 5 + 6 +
    7 + 8 + 9)

Here, the surrounding parentheses ( ) do the line continuation implicitly. Same is the case with [ ] and { }. For example:

colors = ['red',
          'blue',
          'green']

We can also put multiple statements in a single line using semicolons, as follows:

a = 1; b = 2; c = 3

Python Indentation

Most of the programming languages like C, C++, and Java use braces { } to define a block of code. Python, however, uses indentation.

A code block (body of a function, loop, etc.) starts with indentation and ends with the first unindented line. The amount of indentation is up to you, but it must be consistent throughout that block.

Generally, four whitespaces are used for indentation and are preferred over tabs. Here is an example.

for i in range(1,11):
    print(i)
    if i == 5:
        break

The enforcement of indentation in Python makes the code look neat and clean. This results in Python programs that look similar and consistent.

Indentation can be ignored in line continuation, but it’s always a good idea to indent. It makes the code more readable. For example:

if True:
    print('Hello')
    a = 5

and

if True: print('Hello'); a = 5

both are valid and do the same thing, but the former style is clearer.

Incorrect indentation will result in IndentationError.


Python Comments

Comments are very important while writing a program. They describe what is going on inside a program so that a person looking at the source code does not have a hard time figuring it out.

You might forget the key details of the program you just wrote in a month’s time. So taking the time to explain these concepts in the form of comments is always fruitful.

In Python, we use the hash (#) symbol to start writing a comment.

It extends up to the newline character. Comments are for programmers to better understand a program. Python Interpreter ignores comments.

#This is a comment
#print out Hello
print('Hello')

Multi-line comments

We can have comments that extend up to multiple lines. One way is to use the hash(#) symbol at the beginning of each line. For example:

#This is a long comment
#and it extends
#to multiple lines

Another way of doing this is to use triple quotes, either ”’ or “””.

These triple quotes are generally used for multi-line strings. But they can be used as a multi-line comment as well. Unless they are not docstrings, they do not generate any extra code.

"""This is also a
perfect example of
multi-line comments"""

To learn more about comments, visit Python Comments.


Docstrings in Python

A docstring is short for documentation string.

Python docstrings (documentation strings) are the string literals that appear right after the definition of a function, method, class, or module.

Triple quotes are used while writing docstrings. For example:

def double(num):
    """Function to double the value"""
    return 2*num

Docstrings appear right after the definition of a function, class, or a module. This separates docstrings from multiline comments using triple quotes.

The docstrings are associated with the object as their __doc__ attribute.

So, we can access the docstrings of the above function with the following lines of code:

def double(num):
    """Function to double the value"""
    return 2*num
print(double.__doc__)

Output

Function to double the value

For Loop in Shell Scripting

Many times we need to execute a certain part of our code to be executed repeatedly. Loop is one of the alternative solutions available in the programing Which saves our time as well as improved the coding standards.

A ‘for loop’ is a bash programming language statement that allows code to be repeatedly executed. A for loop is classified as an iteration statement i.e. it is the repetition of a process within a bash script. For example, you can run UNIX command or task 5 times or read and process a list of files using for a loop. A for loop can be used at a shell prompt or within a shell script itself.

for loop syntax

Numeric ranges for syntax is as follows:

for VARIABLE in 1 2 3 4 5 .. N do command1 command2 commandN done

OR

for VARIABLE in file1 file2 file3 do command1 on $VARIABLE command2 commandN done

OR

for OUTPUT in $(Linux-Or-Unix-Command-Here) do command1 on $OUTPUT command2 on $OUTPUT commandN done

Examples

root@vps43086554:~# for i in 1 2 3 4 5 7 9;do echo “The value of i = “$i; done
The value of i = 1
The value of i = 2
The value of i = 3
The value of i = 4
The value of i = 5
The value of i = 7
The value of i = 9

Printing in the range

root@vps43086554:~# for i in {1..6};do echo “The value of i = “$i; done
The value of i = 1
The value of i = 2
The value of i = 3
The value of i = 4
The value of i = 5
The value of i = 6

Printing in the range with step

root@vps43086554:~# for i in {1..6..2};do echo “The value of i = “$i; done
The value of i = 1
The value of i = 3
The value of i = 5

Printing in the range with step in the reverse

root@vps43086554:~# for i in {6..1..2};do echo “The value of i = “$i; done
The value of i = 6
The value of i = 4
The value of i = 2

Linux ls command

ls syntax

$ ls [options] [file|dir]

ls command options

ls command main options:

optiondescription
ls -alist all files including hidden file starting with ‘.’
ls –colorcolored list [=always/never/auto]
ls -dlist directories – with ‘ */’
ls -Fadd one char of */=>@| to enteries
ls -ilist file’s inode index number
ls -llist with long format – show permissions
ls -lalist long format including hidden files
ls -lhlist long format with readable file size
ls -lslist with long format with file size
ls -rlist in reverse order
ls -Rlist recursively directory tree
ls -slist file size
ls -Ssort by file size
ls -tsort by time & date
ls -Xsort by extension name

ls command examples

You can press the tab button to auto complete the file or folder names.

List directory Documents/Books with relative path:

$ ls Documents/Books

List directory /home/user/Documents/Books with absolute path.

$ ls /home/user/Documents/Books

List root directory:

$ ls /

List parent directory:

$ ls ..

List user’s home directory (e.g: /home/user):

$ ls ~

List with long format:

$ ls -l

Show hidden files:

$ ls -a

List with long format and show hidden files:

$ ls -la

Sort by date/time:

$ ls -t

Sort by file size:

$ ls -S

List all subdirectories:

$ ls *

Recursive directory tree list:

$ ls -R

List only text files with wildcard:

$ ls *.txt

ls redirection to output file:

$ ls > out.txt

List directories only:

$ ls -d */

List files and directories with full path:

$ ls -d $PWD/*

Data types in Python or Different Types of Objects in Python

In Python, everything is treated as an object or instance of an object. So depending on the nature of the objects the instances behave. Accordingly, the nature of data types the data types are categorized into Mutable and Immutable data types.

Every variable in python holds an instance of an object. There are two types of objects in python i.e. Mutable and Immutable objects. Whenever an object is instantiated, it is assigned a unique object id. The type of the object is defined at the runtime and it can’t be changed afterward. However, it’s the state can be changed if it is a mutable object.

To summarise the difference, mutable objects can change their state or contents and immutable objects can’t change their state or content.

Read the post Difference between mutable and immutable data types.

Data Types in Python

There are many data types in python we have discussed a few mostly used data types in this post as mention below table.

ClassDescription Immutable?
boolBoolean ValueYes
intIntegerYes
floatFloating point numberYes
listThe mutable sequence of objects
tupleImmutable sequence of objectsYes
strunorder set of distinct objects
forzensetImmutable form of set classYes
dictAssocestive mapping

Python Mutable vs Immutable

To get started, it’s important to understand that every object in Python has an ID (or identity), a type, and a value, as shown in the following snippet:

age = 42
print(id(age)) # id
print(type(age)) # type
print(age) # value
[Out:]
10966208
<class ‘int’>
42

Once created, the ID of an object never changes. It is a unique identifier for it, and it is used behind the scenes by Python to retrieve the object when we want to use it.

The type also never changes. The type tells what operations are supported by the object and the possible values that can be assigned to it.

The value can either change or not. If it can, the object is said to be mutable, while when it cannot, the object is said to be immutable.

Let’s take a look at an example:

age = 42
print(id(age))
print(type(age))
print(age)age = 43
print(age)
print(id(age))
[Out:]
10966208
<class ‘int’>
42
43
10966240

Has the value of age changed? Well, no. 42 is an integer number, of the type int, which is immutable. So, what happened is really that on the first line, age is a name that is set to point to an int object, whose value is 42.

When we type age = 43, what happens is that another object is created, of the type int and value 43 (also, the id will be different), and the name age is set to point to it. So, we didn’t change that 42 to 43. We actually just pointed age to a different location.

As you can see from printing id(age) before and after the second object named age was created, they are different.

Now, let’s see the same example using a mutable object.

x = [1, 2, 3]
print(x)
print(id(x))x.pop()
print(x)
print(id(x))
[Out:]
[1, 2, 3]
139912816421064
[1, 2]
139912816421064

For this example, we created a list named m that contains 3 integers, 12, and 3. After we change m by “popping” off the last value 3, the ID of m stays the same!

So, objects of type int are immutable and objects of type list are mutable. Now let’s discuss other immutable and mutable data types!

Linux Inbuild self-help commands (help or man or info)

Linux has many commands available which can be very useful. Even it is very powerful when it gets all the available parameters along with the commands. Due to the varsity of the commands available in the Linux, it’s difficult to remember all the commands.

How to use –h or –help?

Launch the terminal by pressing Ctrl+ Alt+ T or just click on the terminal icon in the taskbar. Simply type your command whose usage you to know in the terminal with –h or –help after space and press enter. And you’ll get the complete usage of that command as shown below.

Description

help displays brief summaries of shell builtin commands. If PATTERN is specified, gives detailed help on all commands matching PATTERN, otherwise the list of help topics is printed.

Syntax

help [-dms] [PATTERN ...]

Options

-dOutput short description for each topic.
-mDisplay usage in pseudo-manpage format.
-sOutput only a short usage synopsis for each topic matching.

Examples

help echo

Display a brief description of the builtin shell command echo.

Linux man command

The “man” is a short term for manual page. In unix like operating systems such as linux, man is an interface to view the system’s reference manual.

A user can request to display a man page by simply typing man followed by a space and then argument. Here its argument can be a command, utility or function. A manual page associated with each of these arguments is displayed.

If you will provide a section number in the command, then man will be directed to look into that section number of the manual and that section page will be displayed. And if not, then by default it will display the first page and you have to go through the entire sections in a pre-defined manner.

We’ll read about section number in this tutorial.

Syntax of man:

  1. man [option(s)] keyword(s)  

But generally [option(s)] are not used. Only keyword is written as an argument.

For example,

  1. man ls  

This command will display all the information about ‘ls’ command as shown in the screenshot.

info command in Linux with Examples

infocommand reads documentation in the info format. It will give detailed information for a command when compared with the man page. The pages are made using the texinfo tools because of which it can link with other pages, create menus and easy navigation.

Syntax:

info [OPTION]... [MENU-ITEM...]

Options:

  • -a, –all: It use all matching manuals.
  • -k, –apropos=STRING: It look up STRING in all indices of all manuals.
  • -d, –directory=DIR: It add DIR to INFOPATH.
  • -f, –file=MANUAL: It specify Info manual to visit.
  • -h, –help: It display this help and exit.
  • -n, –node=NODENAME: It specify nodes in first visited Info file.
  • -o, –output=FILE: It output selected nodes to FILE.
  • -O, –show-options, –usage: It go to command-line options node.
  • -v, –variable VAR=VALUE: It assign VALUE to Info variable VAR.
  • –version: It display version information and exit.
  • -w, –where, –location: It print physical location of Info file.

Examples:

  • -a : It use all matching manuals and displays them for a particular command. info -a cvs

Best Python IDEs And Code Editors

Python is one of the famous high-level programming languages that was developed in 1991.

Python is mainly used for server-side web development, development of software, maths, scripting, and artificial intelligence. It works on multiple platforms like Windows, Mac, Linux, Raspberry Pi etc.

Before exploring more about Python IDE, we must understand what is an IDE!

Python IDE and Code Editors

What You Will Learn: [show]

What is Integrated Development Environment (IDE)

IDE stands for Integrated Development Environment.

IDE is basically a software pack that consist of equipment’s which are used for developing and testing the software. A developer throughout SDLC uses many tools like editors, libraries, compiling and testing platforms.

IDE helps to automate the task of a developer by reducing manual efforts and combines all the equipment’s in a common framework. If IDE is not present, then the developer has to manually do the selections, integrations and deployment process. IDE was basically developed to simplify the SDLC process, by reducing coding and avoiding typing errors.

In contrast to the IDE, some developers also prefer Code editors. Code Editor is basically a text editor where a developer can write the code for developing any software. Code editor also allows the developer to save small text files for the code.

In comparison to IDE, code editors are fast in operating and have a small size. In fact code editors possess the capability of executing and debugging code.

Most Popular Python IDE FAQs

Enlisted below are the most frequently asked questions on Python IDE and Code Editor.

Q  #1) What is IDE and Text or Code Editor?

Answer:

IDE is a development environment which provides many features like coding, compiling, debugging, executing, autocomplete, libraries, in one place for the developer’s thus making tasks simpler whereas Code editor is a platform for editing and modifying the code only.

Q #2) What is the difference between IDE and TEXT EDITOR?

Answer:

IDE and Text Editor can be used in the place of each other for developing any software. Text editor helps the programmer for writing scripts, modifying code or text etc.

But with IDE a programmer can perform several other functions as well like running and executing the code, controlling the version, debug, interpreting, compiling, auto-complete feature, auto linting function, pre-defined functions and in build terminal etc.

IDE can be considered as a development environment where a programmer can write the script, compile and debug the completing process.

IDE also has an integrated file management system and deployment tool. IDE provides support to SVN, CVS, FTP, SFTP, framework etc. Basically, a Text editor is a simple editor to edit the source code and it does not possess any integrated tools or packages.

One advantage of Text editor is that it allows modifying all types of files rather than specifying any particular language or types. Both play an important role in their respective situations when used.

Q #3) Why we need a good Python IDE and how to select one?

Answer:

There are a lot of benefits of using Python IDE like developing a better quality code, debugging feature, justifying why notebooks are handy, getting all the features like compiling and deploying, in one place by making it easier for the developer.

An ideal IDE selection is purely based on the developer requirement like if a developer has to code in multiple languages or any highlighting of syntax or any product compilation is required or more extensibility and the integrated debugger is required or any drag-drop GUI layout is required or features like autocomplete and class browsers are required.

***************

=> Contact us to suggest your listing here

***************

Comparison Table

IDEUser RatingSize in MBDeveloped in
PyCharm
4.5/5BIGJAVA, PYTHON
Spyder
May 4, 2018BIGPYTHON
PyDev
4.6/5MEDIUMJAVA, PYTHON
Idle
4.2/5MEDIUMPYTHON
Wing
May 4, 2018BIGC, C++, PYTHON

Top Python IDEs And Code Editors Comparison

There are several Python IDE and Code editors that are discussed in this article and all the information that is required to choose the best IDE for your organization are explained here.

#1) PyCharm

PyCharm

Type: IDE.

Price: US $ 199 per User – 1st year for Professional Developer.

Platform Support: WINDOWS, LINUX, MAC etc.

Screenshots For Reference:

PyCharm screenshots1
PyCharm screenshots2

PyCharm is one of the widely used Python IDE which was created by Jet Brains. It is one of the best IDE for Python. PyCharm is all a developer’s need for productive Python development.

With PyCharm, the developers can write a neat and maintainable code. It helps to be more productive and gives smart assistance to the developers. It takes care of the routine tasks by saving time and thereby increasing profit accordingly.

Best Features:

  1. It comes with an intelligent code editor, smart code navigation, fast and safe refactoring’s.
  2. PyCharm is integrated with features like debugging, testing, profiling, deployments, remote development and tools of the database.
  3. With Python, PyCharm also provides support to python web development frameworks, JavaScript, HTML, CSS, Angular JS and Live edit features.
  4. It has a powerful integration with IPython Notebook, python console, and scientific stack.

Pros:

  1. It provides a smart platform to the developers who help them when it comes to auto code completion, error detection, quick fixing etc.
  2. It provides multiple framework support by increasing a lot of cost-saving factors.
  3. It supports a rich feature like cross-platform development so that the developers can write a script on different platforms as well.
  4. PyCharm also comes with a good feature of the customizable interface which in turn increases the productivity.

Cons:

  1. PyCharm is an expensive tool while considering the features and the tools it provides to the client.
  2. The initial installation is difficult and may hang up in between sometimes.

Official URL: Pycharm

#2) Spyder

Spyder

Type: IDE.

Price: Open Source

Platform Support: QT, WINDOWS, LINUX, MAC OS etc.

Screenshots For Reference:

Spyder1
Spyder2

SPYDER is another big name in the IDE market. It is a good python compiler.

It is famous for python development. It was mainly developed for scientists and engineers to provide a powerful scientific environment for Python. It offers an advanced level of edit, debug, and data exploration feature. It is very extensible and has a good plugin system and API.

As SPYDER uses PYQT, a developer can also use it as an extension. It is a powerful IDE.

Best Features:

  1. It is a good IDE with syntax highlighting, auto code completion feature.
  2. SPYDER is capable of exploring and editing variables from GUI itself.
  3. It works perfectly fine in multi-language editor along functions and auto code completion etc.
  4. It has a powerful integration with ipython Console, interacts and modifies the variables on the go as well, hence a developer can execute the code line by line or by the cell.

Pros:

  1. It is very efficient in finding and eliminating the bottlenecks to unchain the code performance.
  2. It has a powerful debugger to trace each step of the script execution smoothly.
  3. It has a good support feature to instantly view any object documents and modify your own documents.
  4. It also supports extended plugins to improvise its functionality to the new level.

Cons:

  1. It is not capable of configuring which warning the developer wants to disable.
  2. Its performance reduces when too many plugins are invoked at the same time.

Official URL: SPYDER

#3) Pydev

PyDev

Type: IDE

Price: Open Source

Platform Support: QT, WINDOWS, LINUX, MAC OS etc.

Screenshots For Reference:

PyDev screenshot1
PyDev screenshot2
PyDev screenshot3

PyDev is an outside plugin for Eclipse.

It is basically an IDE that is used for Python development. It is linear in size. It mainly focuses on the refactoring of python code, debugging in the graphical pattern, analysis of code etc. It is a strong python interpreter.

As it’s a plugin for eclipse it becomes more flexible for the developers to use the IDE for development of an application with so many features. In open source IDE, it is one of the preferred IDE by the developers.

Best Features:

  1. It is a nice IDE with Django integration, auto code completion and code coverage feature.
  2. It supports some rich features like type hinting, refactoring, debugging, and code analysis.
  3. PyDev supports PyLint integration, tokens browser, interactive console, Unittest integration, and remote debugger etc.
  4. It also supports Mypy, black formatter, virtual environments, and analyzing f-strings.

Pros:

  1. PyDev provides a strong syntax high lighting, parser errors, code folding, and multi-language support.
  2. It has a good outline view, it marks occurrences as well and has an interactive console.
  3. It has good support for CPython, Jython, Iron Python, and Django and allows interactive probing in suspended mode.
  4. It provides tabs preferences, smart indent, Pylint integration, TODO tasks, auto-completion of keywords and content assistants.

Cons:

  1. Sometimes the plugins in PyDev become unstable by creating issues in the development of the application.
  2. Performance of PyDev IDE decreases if the application is too big with multiple plugins.

Official URL: PyDev

#4) Idle

PyDev

Type: IDE.

Price: Open Source.

Platform Support: WINDOWS, LINUX, MAC OS etc.

Screenshots For Reference:

PyDev SCREENSHOT1
PyDev SCREENSHOT2

IDLE is a popular Integrated Development Environment written in Python and it has been integrated with the default language. It is one of the best IDE for python.

IDLE is a very simple and basic IDE which is mainly used by the beginner level developers who want to practice on python development. It is also a cross-platform thus helping the trainee developers a lot but it also called as a disposable IDE as a developer moves to more advance IDE after learning the basics.

Best Features:

  1. IDLE is developed purely in Python with the usage of Tkinter GUI toolkit and is also a cross-platform thereby increasing the flexibility for developers.
  2. It has a good feature of multi-window text editor which has many features like call tips, smart indentation, undo and python colorizing.
  3. It has a powerful debugger with continuous breakpoints, global view, and local spaces.
  4. It also supports dialog boxes, browsers, and editable configurations.

Pros:

  1. IDLE also supports syntax highlighting, auto code completion and smart indentation like other IDE’s.
  2. It has a Python shell with a high lighter.
  3. Integrated debugger with call stack visibility which increases the performance of developers.
  4. In IDLE, a developer can search within any window, search through multiple files and replace within the windows editor.

Cons:

  1. It has some normal usage issues, sometimes it lacks focus, and the developer cannot directly copy to the dashboard.
  2. IDLE does not have the numbering of line option which is a very basic design of the interface.

Official URL: IDLE

#5) Wing

WING

Type: IDE

Price: US $ 95 to US $ 179 PER USER FOR COMMERCIAL USE.

Platform Support: WINDOWS, LINUX, MAC OS etc.

Screenshots For Reference:

WING screenshot1
WING screenshot2
WING screenshot3

Wing is also a popular and powerful IDE in today’s market with a lot of good features which the developers require for python development.

It comes with a strong debugger and smart editor that makes the interactive Python development speed, accurate and fun to perform. Wing also provides a 30-day trial version for the developers to have a taste on its features.

Best Features:

  1. Wing helps in moving around the code with go-to-definition, find the uses and symbol’s in the application, edit symbol index, source browser, and effective multiple-file search.
  2. It supports the test-driven development with unit test, pytest, and Django testing framework.
  3. It assists remote development and is customizable and extensible too.
  4. It also has auto code completion, the error is displayed in a feasible manner and line editing is also possible.

Pros:

  1. In case of expiration of trial version, Wing provides around 10 minutes to the developers to migrate their application.
  2. It has a source browser which helps to show all the variables which are used in the script.
  3. Wing IDE provides an additional exception handling tab which helps a developer to debug the code.
  4. It provides an extract function which is under the refactor panel and is also a good help for the developers for increasing performance.

Cons:

  1. It is not capable of supporting dark themes which many developers like to use.
  2. Wing interface can be intimidating at the starting and the commercial version is way too expensive.

Official URL: Wing

#6) Eric Python

Eric Python

Type: IDE.

Price: Open Source.

Platform Support: WINDOWS, LINUX, MAC OS etc.

Screenshots For Reference:

eric python1
Eric Python screenshot2
eric python3

Eric is powerful and is rich in feature Python IDE and editor which is developed in Python itself. Eric can be used on the daily activity purpose or for the professional developers as well.

It is developed on cross-platform QT toolkit which is integrated with flexible Scintilla editor. Eric has an integrated plugin system which provides a simple extension to the IDE functions.

Best Features:

  1. ERIC has many editors, configurable window layout, source code folding and call tips, error high lighting, and advanced search functions.
  2. It has an advanced project management facility, integrated class browser, version control, cooperation functions, and source code.
  3. It offers cooperation’s functions, inbuilt debugger, inbuilt task management, profiling and code coverage support.
  4. It supports application diagram’s, syntax highlighting and auto code completion feature.

Pros:

  1. ERIC allows integrated support for unittest, CORBA and google protobuf.
  2. It has a lot of wizards for regex, QT dialogs, and tools for previewing QT forms and translations by making the developer’s task easier.
  3. It supports web browsers and has a spell check library which avoids errors.
  4. It also supports localization and has a rope refactoring tool for development.

Cons:

  1. ERIC installation becomes clumsy sometimes and it does not have a simple and easy GUI.
  2. When the developers try to integrate too many plugins the productivity and performance of the IDE decreases.

Official URL: Eric Python

#7) Rodeo

Rodeo

Type: IDE.

Price: Open Source.

Platform Support: WINDOWS, LINUX, Mac OS etc.

Screenshots For Reference:

Rodeo
RODEO screenshots2

Rodeo is one of the best IDE for python that was developed for data science-related tasks like taking data and information from different resources and also plotting for issues.

It supports cross-platform functionality. It can also be used as an IDE for experimenting in an interactive manner.

Best Features:

  1. It supports all the functions which are required for data science or machine learning tasks like loading data and experimenting in some manner.
  2. It allows the developers to interact, compare data, inspect and plot.
  3. Rodeo provides a clean code, auto-completion of code, syntax high lighting, and IPython support to write the code faster.
  4. It also has visual file navigator, clicks and point the directories, package search makes it easier for a developer to get what they want.

Pros:

  1. It is a lightweight, highly customizable and intuitive development environment which makes it unique.
  2. It has both text editor and me Python console.
  3. It includes all the supporting documentation at the last tab for better understanding.
  4. It has Vim, Emacs mode and allows single or block execution of code.
  5. Rodeo can also auto-update its latest version.

Cons:

  1. It is not maintained properly.
  2. No extended support facilities from the company staff in case of issues.

Official URL: Rodeo

#8) Thonny

Thonny IDE

Type: IDE.

Price: Open Source.

Platform Support: WINDOWS, LINUX, Mac OS etc.

Screenshots For Reference:

Thonny screenshot1
Thonny screenshot2
Thonny screenshot3

Thonny IDE is one of the best IDE for the beginner’s who have no prior Python experience to learn Python development.

It is very basic and simple in terms of features which even the new developers easily understand. It is very helpful for the users who use the virtual environment.

Best Features:

  1. Thonny provides the ability to the users to check how the programs and shell commands affect the python variables.
  2. It provides a simple debugger with F5, F6 and F7 function keys for debugging.
  3. It offers the ability to a user to see how python internally evaluates the written expression.
  4. It also supports the good representation of function calls, highlighting errors and auto code completion feature.

Pros:

  1. It has a very simple and clean Graphical user interface.
  2. It is very friendly for the beginners and takes care of PATH and issues with other python interpreters.
  3. The user has the ability to change the mode for explaining the reference.
  4. It helps to explain the scopes by highlighting the spots.

Cons:

  1. The interface design is not at all good and is limited to text editing and also has a lack of support for templates.
  2. Creation of plugin is really slow and there are many features which are lacking for developers.

Official URL: Thonny

Best Python Code Editors

Code editors are basically the text editors which are used to edit the source code as per the requirements.

These may be integrated or stand-alone applications. As they are monofunctional, they are very faster too. Enlisted below are some of the top code editors which are preferred by the Python developer’s world-wide.

#1) Sublime Text

Sublime Text

Type: Source Code Editor.

Price: USD $80.

Platform Support: WINDOWS, LINUX, Mac OS etc.

Screenshots For Reference:

Sublime Text screenshot1
Sublime Text screenshot2

Sublime Text is a very popular cross-platform text editor developed on C++ and Python and also have a Python API.

It is developed in such a manner that it supports many other programming and markup languages. It allows a user to add other functions with the help of plugins. It is more reliable when compared to the other code editors as the per developers review.

Best Features:

  1. Sublime text has GOTO anything for opening files with few clicks and can navigate to words or symbols.
  2. It has a strong feature of multiple selections to change many things at one time and also a command palette to sort, change the syntax, change indentation etc.
  3. It has high performance, powerful API and package ecosystem.
  4. It is highly customizable, allows split editing, allows instant project switch and is also cross-platform.

Pros:

  1. It has good compatibility with language grammars.
  2. It allows a user to choose specific preference related to projects.
  3. It also has a GOTO Definition feature to generate an application wide index of each method, class, and function.
  4. It shows high performance and has a powerful cross-platform User interface toolkit.

Cons:

  1. Sublime text can sometimes be intimidating to new users initially.
  2. It does not have a strong GIT plugin.

Official URL: Sublime Text

#2) Atom

Atom

Type: Source Code Editor.

Price: Open Source.

Platform Support: WINDOWS, LINUX, Mac OS etc.

Screenshots For Reference:

Atom screenshot1
Atom screenshot2

Atom is a free source code editor and is basically a desktop application which is built through a web technology having plugin support that is developed in Node.js.

It is based on atom shells which are a framework that helps to achieve cross-platform functionality. The best thing is that is can also be used as an Integrated Development Environment.

Best Features:

  1. Atom works on cross-platform editing very smoothly thereby increasing the performance of its users.
  2. It also has a built-in package manager and file system browser.
  3. It helps the users to write script faster with a smart and flexible auto-completion.
  4. It supports multiple pane features, finds and replaces text across an application.

Pros:

  1. It is simple and really simple to use.
  2. Atom allows UI customization to its user.
  3. It has a lot of support from the crew at GitHub.
  4. It has a strong feature for quickly opening the file to retrieve data and information.

Cons:

  1. It takes more time to sort the configurations and plugins as it’s a browser-based app.
  2. Tabs are clumsy, reduces the performance and sometimes loads slowly.

Official URL: Atom

#3) Vim

Vim

Type: Source Code Editor.

Price: Open Source.

Platform Support: WINDOWS, LINUX, Mac OS, IOS, Android, UNIX, AmigaOS, MorphOS etc.

Screenshots For Reference:

Vim screenshot1
Vim screenshot2

Vim is a popular open source text editor which is used to create and modify any type of text and is highly configurable.

According to the developers, VIM is a very stable text editor and its quality of performance is increasing on each new release of it. Vim text editor can be used as command line interface as well as standalone application.

Best Features:

  1. VIM is very persistent and also have a multilevel undo tree.
  2. It comes with an extensive system of plugins.
  3. It provides a wide range of support for many programming languages and files.
  4. It has a powerful integration, search and replace functionality.

Pros:

  1. Vim provides two different modes to the user to work i.e. Normal mode and editing mode.
  2. It comes with its own scripting language which allows a user to modify behavior and custom functionality.
  3. It also supports the non-programming applications which every other editor does not have.
  4. Strings in VIM are nothing but command sequences so that the developer can save and again reuse them.

Cons:

  1. It is only a text edit tool and doesn’t have a different color for the pop up shown.
  2. It does not have an easy learning curve and becomes difficult to learn at the beginning.

Official URL: VIM

#4) Visual Studio Code

Visual Studio Code

Type: Source Code Editor.

Price: Open Source.

Platform Support: WINDOWS, LINUX, Mac OS etc.

Screenshots For Reference:

Visual Studio

Visual Studio Code is an open source code editor which was developed mainly for the development and debugging of latest web and cloud projects.

It is capable of combining both editor and good development features very smoothly. It is one of the major choices for python developers.

Best Features:

  1. It supports syntax highlighting and auto code complete feature with IntelliSense which completes syntax based on variable types, function definition etc.
  2. It has a powerful debugger and the user can debug from the editor itself.
  3. It has strong integration with GIT so that a user can perform GIT operations like push, commit straight from the editor itself.
  4. Visual studio is highly extensible and customizable through which we can add languages, debuggers, themes etc.

Pros:

  1. It provides multi-language support and many other functionalities which the other languages don’t possess.
  2. It has a good layout and smart interface.
  3. It allows the use of many plugins which a developer can get from the VS code marketplace for its customization.
  4. It supports the use of vertical orientation and multi-split window feature.

Cons:

  1. Searching with visual studio code is very slow.
  2. Initially, it takes an ample amount of time to launch.

Official URL: Visual Studio

Summary

We hope this article would have given you a clear picture of what Python IDE and Source Code Editors are.

What is the major difference between both of them and why Python developers use Python IDE for development of web or cloud applications? How the IDE’s are improving the performance of developers and thereby increase the profit.

The topmost Python IDE which is preferred by most of the developers worldwide is covered in this article. We have also seen the benefits and demerits of each IDE based on which the developers decide to select which IDE is best for their project.

Large Scale Business: As these industries have both Finance and manpower, they prefer IDE’s like PyCharm, Atom, Sublime Text, Wing etc., so that they can get all the features with extended support from the companies for all their issues.

Middle and Small Scale Business: As these industries lookout for tools which are Open source and cover most of the features, they mostly prefer Spyder, PyDev, IDEL, ERIC Python and visual studio code for their projects.

Groovy – Variables

Variables in Groovy can be defined in two ways − using the native syntax for the data type or the next is by using the def keyword. For variable definitions, it is mandatory to either provide a type name explicitly or to use “def” in replacement. This is required by the Groovy parser.

There are following basic types of variable in Groovy as explained in the previous chapter −

  • byte − This is used to represent a byte value. An example is 2.
  • short − This is used to represent a short number. An example is 10.
  • int − This is used to represent whole numbers. An example is 1234.
  • long − This is used to represent a long number. An example is 10000090.
  • float − This is used to represent 32-bit floating-point numbers. An example is 12.34.
  • double − This is used to represent 64-bit floating-point numbers which are longer decimal number representations which may be required at times. An example is 12.3456565.
  • char − This defines a single character literal. An example is ‘a’.
  • Boolean − This represents a Boolean value which can either be true or false.
  • String − These are text literals that are represented in the form of a chain of characters. For example “Hello World”.

Groovy also allows for additional types of variables such as arrays, structures, and classes which we will see in the subsequent chapters.

Variable Declarations

A variable declaration tells the compiler where and how much to create the storage for the variable.

Following is an example of variable declaration

class Example { 
   static void main(String[] args) { 
      // x is defined as a variable 
      String x = "Hello";
		
      // The value of the variable is printed to the console 
      println(x);
   }
}

When we run the above program, we will get the following result −

Hello

Naming Variables

The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because Groovy, just like Java is a case-sensitive programming language.

class Example { 
   static void main(String[] args) { 
      // Defining a variable in lowercase  
      int x = 5;
	  
      // Defining a variable in uppercase  
      int X = 6; 
	  
      // Defining a variable with the underscore in it's name 
      def _Name = "Joe"; 
		
      println(x); 
      println(X); 
      println(_Name); 
   } 
}

When we run the above program, we will get the following result −

5 
6 
Joe 

We can see that x and X are two different variables because of case sensitivity and in the third case, we can see that _Name begins with an underscore.

Printing Variables

You can print the current value of a variable with the println function. The following example shows how this can be achieved.

class Example { 
   static void main(String[] args) { 
      //Initializing 2 variables 
      int x = 5; 
      int X = 6; 
	  
      //Printing the value of the variables to the console 
      println("The value of x is " + x + "The value of X is " + X);  
   }
}

When we run the above program, we will get the following result −

The value of x is 5 The value of X is 6 

Loops and Control Statements in Groovy

While Loop

The syntax of the while statement is shown below −

while(condition) { 
   statement #1 
   statement #2 
   ... 
}

The while statement is executed by first evaluating the condition expression (a Boolean value), and if the result is true, then the statements in the while loop are executed. The process is repeated starting from the evaluation of the condition in the while statement. This loop continues until the condition evaluates to false. When the condition becomes false, the loop terminates. The program logic then continues with the statement immediately following the while statement. The following diagram shows the diagrammatic explanation of this loop.

Following is an example of a while loop statement

class Example {
   static void main(String[] args) {
      int count = 0;
		
      while(count<5) {
         println(count);
         count++;
      }
   }
}

In the above example, we are first initializing the value of a count integer variable to 0. Then our condition in the while loop is that we are evaluating the condition of the expression to be that count should be less than 5. Till the value of count is less than 5, we will print the value of count and then increment the value of count. The output of the above code would be −

0 
1 
2 
3 
4

For Loop

Following is an example of a while loop statement

class Example {
   static void main(String[] args) {
      int count = 0;
		
      while(count<5) {
         println(count);
         count++;
      }
   }
}

In the above example, we are first initializing the value of a count integer variable to 0. Then our condition in the while loop is that we are evaluating the condition of the expression to be that count should be less than 5. Till the value of count is less than 5, we will print the value of count and then increment the value of count. The output of the above code would be −

0 
1 
2 
3 
4

for-in statement

The for-in statement is used to iterate through a set of values. The for-in statement is generally used in the following way.

for(variable in range) { 
   statement #1 
   statement #2 
   … 
}

The following diagram shows the diagrammatic explanation of this loop.

Following is an example of a for-in statement −

class Example { 
   static void main(String[] args) { 
      int[] array = [0,1,2,3]; 
		
      for(int i in array) { 
         println(i); 
      } 
   } 
}

In the above example, we are first initializing an array of integers with 4 values of 0,1,2 and 3. We are then using our for loop statement to first define a variable i which then iterates through all of the integers in the array and prints the values accordingly. The output of the above code would be −

0 
1 
2 
3

The for-in statement can also be used to loop through ranges. The following example shows how this can be accomplished.

class Example {
   static void main(String[] args) {
	
      for(int i in 1..5) {
         println(i);
      }
		
   } 
} 

In the above example, we are actually looping through a range which is defined from 1 to 5 and printing the each value in the range. The output of the above code would be −

1 
2 
3 
4 
5 

The for-in statement can also be used to loop through Map’s. The following example shows how this can be accomplished.

class Example {
   static void main(String[] args) {
      def employee = ["Ken" : 21, "John" : 25, "Sally" : 22];
		
      for(emp in employee) {
         println(emp);
      }
   }
}

In the above example, we are actually looping through a map that has a defined set of key-value entries. The output of the above code would be −

Ken = 21 
John = 25 
Sally = 22 

Break Statement

The break statement is used to alter the flow of control inside loops and switch statements. We have already seen the break statement in action in conjunction with the switch statement. The break statement can also be used with a while and for statements. Executing a break statement with any of these looping constructs causes immediate termination of the innermost enclosing loop.

The following diagram shows the diagrammatic explanation of the break statement.

Following is an example of the break statement

class Example {
   static void main(String[] args) {
      int[] array = [0,1,2,3];
		
      for(int i in array) {
         println(i);
         if(i == 2)
         break;
      }
   } 
}

The output of the above code would be −

0 
1 
2 

As expected since there is a condition put saying that if the value of i is 2 then break from the loop that is why the last element of the array which is 3 is not printed.

Continue Statement

The continue statement complements the break statement. Its use is restricted to while and for loops. When a continue statement is executed, control is immediately passed to the test condition of the nearest enclosing loop to determine whether the loop should continue. All subsequent statements in the body of the loop are ignored for that particular loop iteration.

The following diagram shows the diagrammatic explanation of the continue statement −

Following is an example of the continue statement

class Example {
   static void main(String[] args) {
      int[] array = [0,1,2,3];
		
      for(int i in array) {
         println(i);
         if(i == 2)
         continue;
      }
   }
}

The output of the above code would be −

0 
1 
2 
3

Data Types in Groovy

In any programming language, you need to use various variables to store various types of information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory to store the value associated with the variable.

You may like to store information on various data types like string, character, wide character, integer, floating-point, Boolean, etc. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.

Built-in Data Types

Groovy offers a wide variety of built-in data types. Following is a list of data types which are defined in Groovy −

  • byte − This is used to represent a byte value. An example is 2.
  • short − This is used to represent a short number. An example is 10.
  • int − This is used to represent whole numbers. An example is 1234.
  • long − This is used to represent a long number. An example is 10000090.
  • float − This is used to represent 32-bit floating-point numbers. An example is 12.34.
  • double − This is used to represent 64-bit floating-point numbers which are longer decimal number representations which may be required at times. An example is 12.3456565.
  • char − This defines a single character literal. An example is ‘a’.
  • Boolean − This represents a Boolean value which can either be true or false.
  • String − These are text literals that are represented in the form of a chain of characters. For example “Hello World”.

Bound values

The following table shows the maximum allowed values for the numerical and decimal literals.

byte-128 to 127
short-32,768 to 32,767
int-2,147,483,648 to 2,147,483,647
long-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
float1.40129846432481707e-45 to 3.40282346638528860e+38
double4.94065645841246544e-324d to 1.79769313486231570e+308d

Class Numeric

Types In addition to the primitive types, the following object types (sometimes referred to as wrapper types) are allowed −

  • java.lang.Byte
  • java.lang.Short
  • java.lang.Integer
  • java.lang.Long
  • java.lang.Float
  • java.lang.Double

In addition, the following classes can be used for supporting arbitrary precision arithmetic −

NameDescriptionExample
java.math.BigIntegerImmutable arbitrary-precision signed integral numbers30g
java.math.BigDecimalImmutable arbitrary-precision signed decimal numbers3.5g

The following code example showcases how the different built-in data types can be used

class Example { 
   static void main(String[] args) { 
      //Example of a int datatype 
      int x = 5; 
		
      //Example of a long datatype 
      long y = 100L; 
		
      //Example of a floating point datatype 
      float a = 10.56f; 
		
      //Example of a double datatype 
      double b = 10.5e40; 
		
      //Example of a BigInteger datatype 
      BigInteger bi = 30g; 
		
      //Example of a BigDecimal datatype 
      BigDecimal bd = 3.5g; 
		
      println(x); 
      println(y); 
      println(a); 
      println(b); 
      println(bi); 
      println(bd); 
   } 
}

When we run the above program, we will get the following result −

5 
100 
10.56 
1.05E41 
30 
3.5