DEV Community

Cover image for Python: A Beginner's Guide
RCharlotte
RCharlotte

Posted on

Python: A Beginner's Guide

One of the more difficult things about enjoying challenges is that I naturally gravitate towards more difficult, tasking, cumbersome and demanding tasks, people, you name it. And as I ventured into coding, I still am no different. I began with C, followed closely by Java, and found myself thoroughly enjoying the infamously long syntaxes of the latter.
So yes, Java is a first love. A memorable part of my programming and coding journey. But, when I was introduced to python, I knew the rubber had met the road, and there was no looking back.

**

So, Why Python?

**

  1. Ease of use- Python has one of the easier and more flexible syntax rules that I have come across. If you have worked with Dart in Flutter, you know that code is not the only thing you have to worry about, with the strict punctuation rules of commas and full stops that can throw you off at any time.

  2. Versatility- From a simple Fibonacci sequence, website development, and complex machine learning algorithms, its capacity is undeniable.

  3. Popularity- Python has quickly risen to the big leagues alongside veteran languages such as Java. I will go out on a limb, and say that it is one of the most sought-after skills in the software job market currently, and as is, a great add to your portfolio.

I wouldn't do this space justice if I did not share this remarkable tool with you, and showed you how to get started with Python:

1. Installing Python in your machine

The easiest way to do this is to download a Python Installer, which will do all the heavy-lifting for you at Python Official Page. Make sure to install a version that is secure, and stable. This is not necessarily the latest version, and will be labelled security under the maintenance status column. The version you choose should also be compatible with your operating system.

2. Installing A Suitable Text Editor

Visual Studio Code is a popular choice, due to the fact that it enables compilation of various programming languages, and not just Python. It still runs fairly fast on low-specs such as 4GB RAM machines, so you have nothing to worry about. Well, provided you are not trying to run too many applications alongside it, you're PC will be just fine. You can download the latest version here.

To be able to write Python code on VS Code, it is helpful to install a python extension, as shown below.

  1. Select the extension button to the left of the Interface.
  2. Select the first python extension.
  3. Select the install button, and prepare to start your first coding project.

Installing a Python Extension in VS Code

3. Get Coding!

  1. Create a folder in a preferred location on your PC.
  2. Navigate to VS Code, and select the File tab, followed by Open Folder, then select your created file.
  3. Once open, click on new file, and give it a suitable name, and remember to add .py at the end of your chosen name. For example, in this example, my file name is HelloWorld.py.

.py enables the Python interpreter to identify the file and run it as python code.

Creating your First Python File in VS Code

Select the Run and Debug button to the left of your VSCode Interface, and this will be the output on your terminal

VS Terminal Screen

The python script is:


print ('From Hello World to Changing the World')

Enter fullscreen mode Exit fullscreen mode

Now, how simple was that?

Other versions of this can be written to increase flexibility and versatility of the code, as below:

Statement = 'From Hello World to Changing the World'

print (Statement)

Enter fullscreen mode Exit fullscreen mode

To better understand what is happening, I will explain the rules of Python at play here.

As we are trying to print a statement to the terminal, we can take advantage of Python's rich functions, and use the print() function.
A function is a section of code meant to perform a specific task. In this case, the task is to print. Although you can create functions for yourself, the essence of high level programming is to increase your productivity, by ensuring that you do not re-invent the wheel, or waste time and energy creating inbuilt functions.

print() accepts anything between its parenthesis, provided it follows a particular data-type known as String.
A data-type classifies data items so that you, and the interpreter know what operations can be carried out on a data item. A string data type is denoted using single quotes '' , double quotes, "" , or triple quotes """ .

In this example, we use single quotes in 'From Hello World to Changing the World'

In the second version, we use a variable/identifier to initialize and define the String. If any changes need to be made, therefore, we can alter the text from Statement, and this helps us to separate areas of concern.

The other 4 Standard data types that can be used in Python are Numbers, List, Tuple and Dictionary, which I will discuss in my future posts. For now, you can access this information at Rhino Developer Docs.

Now, as we are journeying on professional coding, we have to remember the importance of writing clear code. This begins by using comments.

In python, comments are not executed, and are ignored by the Compiler. They are used to enhance understanding and readability of your code, and are denoted by #, for a single line comment and triple quotes for a multi-line comment """ """
A single line comment will be as follows:

# My First Python Code

Statement = 'From Hello World to Changing the World'

print (Statement)

Enter fullscreen mode Exit fullscreen mode

A multiple-line comment will be written as follows:


"""
This is my First Python Program

I love to code

"""
Statement = 'From Hello World to Changing the World'

print (Statement)

Enter fullscreen mode Exit fullscreen mode

As you have seen, Python is easy to follow, and can be a powerful tool once you have mastered its ins and outs. It is no wonder that it has become that: Python, My Second Love.

image credits: Link

Latest comments (0)