DEV Community

Cover image for What is Python?
JSteigner
JSteigner

Posted on

What is Python?

Hello! This week I'll be giving a brief introduction to the programming language Python!

Python was created by Guido van Rossum and released in 1991. It was a successor to the ABC programming language which Rossum was also involved in creating. Python was originally started as a hobby to keep Guido busy during a Christmas vacation and has evolved to be one of the most popular languages used today. The mysterious name is a homage to 'Monty Python's Flying Circus'!

Alt Text

According to Geeks for Geeks, Python "was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code." Python is more akin to the English language than other programming languages are. It is also similar to the mathematics language.

Python is commonly used for server-side web development. It is also used for software development, mathematics, machine-learning, and system scripting. It can run on all the different popular platforms. Python runs on it's own interpreter system, so code can be quickly executed as soon as it's written.

A couple key differences when dealing with Python from other languages is it's use of a new line to complete commands instead of parentheses or a semi-colon, and Python uses indentation(white-space) to define scope.

To use Python you will need to check if it's installed. This can be done by running this command in your terminal: python3 --version. You may have an older version of Python installed so you may need to run python --version or python2 --version but python3 worked for me. You can go to the Python website if you need to install it. According to W3Schools "Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed." So to run a file you need to prefix the 'your-file-name'.py file you want to run with the 'python3' command so the file will be supplied to the correct interpreter. Let's look at an example:

Alt Text

Here is a simple Python command that 'prints' a string to the console. Now this command to run the file:

Alt Text

since the name of the interpreter is python3 and the file to be run is demo.py. The result of the 'print' command is shown in the console. This is similar to calling 'console.log()' in JavaScript.

Python also has its own command line and you can access it by typing the interpreter name in the console, in this case 'python3'.

Alt Text

You can then run commands simply from the command line instead of creating a whole file, which makes testing code much easier.

Alt Text

As mentioned earlier, indentation is really important in Python because it establishes a code block. If you try to write a block of code without indentation, an error will occur. The amount of whitespace used needs to be at least one and if multiple lines are used inside the code block, the indentation must match. This is in contrast to JavaScript where whitespace is used only for easy reading.

Alt Text

In Python, to create a variable you just need to assign a value to it and there are no variable declarations.

Alt Text

Python supports commenting but instead of the forward slash(/) the pound sign(#) is used. There are no multi-line comments so each commented line must begin with a pound sign.

Alt Text

Here only 'No they definitely don't say 'Ni' gets printed to the console.

Alt Text

In conclusion, Python is a programming language that was built to make programming easier and more intuitive than some of the other languages out there. Its supported by all the major platforms and is very popular! Thanks for reading!

Latest comments (0)