fbpx

Python, named after the British comedy group Monty Python, is a popular high-level, interpreted, interactive, and object-oriented programming language, it is described as one of the simplest programming languages. 

The purpose of its development is to simplify the learning process of a programming language, also, to display to beginners the concepts of programming easily.

Python can be used on a server to create web applications, with the aid of python, you can write basic programs and scripts, creating solutions for complex and large-scale enterprises.

This article entails 7 easy steps on how to learn code with python. With the aid of this article, your child/ren will learn to write and run their first code using python. This article contains step-by-step fundamental knowledge needed to code with python. 

There are different software applications used in writing Python codes, they can also be referred to as Python IDEs or code Editors. These softwares make it easy and simplified for your python code. With the aid of these IDEs and editors, your python codes can be created. 

Top code editors or IDEs for python:

  • PyCharm.
  • Visual Studio Code.
  • Sublime Text.
  • Vim.
  • Atom.
  • Jupyter Notebook.
  • Eclipse + PyDev + LiClipse.
  • GNU Emacs.

Visual studio code is one of the most used code editors today, it can be used to write your code in Python. See the diagram of  Visual Studio Code below:

visual studio code

In order to practice, you can download Visual Studio Code following these simple steps 

Steps to Download and Install Visual Studio Code

  • Type in ‘Visual studio Code’ on your web browser 
  • Visit: https://code.visualstudio.com/
  • Select ‘download’, different options pop out, select ‘Windows 8,10, 11’ for non-apple systems; for apple systems, select ‘Mac’
  • It automatically downloads in a few minutes, from the download icon, select ‘Show in folder’ 
  • It takes you to the page of installing the application, select ‘Install’ and follow every other instruction/step given.
  • After doing that, the ‘Finish’ button pops up, select the button it takes you back to your desktop 
  • Select the already downloaded application, and following the necessary steps, it takes you to the visual studio editor as seen above

Before go into the 7 easy steps on how to learn to code with python, there are some basic concepts you need to understand. 

Having the knowledge of these concepts about python programming will put you ahead of others. These concepts are absolutely important and necessary when it comes to python programming. We shall be looking at those concepts which are otherwise called ‘The Basic Python Syntax’

The Python syntax is concise, simplified, clear and it is focused on its readability. Readability is one of the many features of python which makes it attractive. There are several components of the python syntax which are listed below: 

Python Code Keywords

  • Comments
  • Variables 
  • Keywords
  • Conditional Statements 
  • Control flow
  • Lists
  • Functions
  • String
  • Dictionary 
  • Files
  • Indentations

Comments: Comments are used to describe the codes in order for developers to understand the function of the code or the reason the code is written in a specific way. Comments can be described as pieces of text that are embedded in your codes which are constantly ignored by the Python interpreter as it executes the code. 

To write a ‘Comment’ in Python,  just add a hashtag symbol{#} before the comment text. 

# This is a comment on its own line

Inline comments can also be added to your code; a comment in a single line can be combined with a python expression, provided that the comment occupies the final part of the same line. 

var = “Hello, World!”  # This is an inline comment

Variables: In Python, variables are names given to a particular subject, these variables serve as a reference to the memory address as to which the object is stored. It is worth noting that you can access the object using the variable name once a variable is assigned to an object. You can define your variables using the syntax below:  

variable_name = variable_value

Sometimes programmers use short variable names, such as x and y. These are perfectly suitable names in the context of math, algebra, and so on. In other contexts, you should avoid single-character names and use something more descriptive. That way, other developers can make an educated guess of what your variables hold. 

Pro tip: Think of others, as well as your future self, when writing your programs.

Examples of valid and invalid variables names in Python:

>>>

>>> numbers = [1, 2, 3, 4, 5]

>>> numbers

[1, 2, 3, 4, 5]

>>> first_num = 1

>>> first_num 

1

Keywords: Python has a set of unique words that are part of its syntax; these words are known as Keywords. Each of these plays a vital role in Python Syntax, they are reserved words that have specific meanings. They should not be used for any other purpose but those specific purposes, these variables should not be used as variable names in your code.

To see the list of keywords in python simply type the word ‘help(“keywords”)

>>>

>>> help(“keywords”)

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or

None                continue            global              pass

True                def                 if                  raise

and                 del                 import              return

as                  elif                in                  try

assert              else                is                  while

async               except              lambda              with

await               finally             nonlocal            yield

break               for                 not

>>>

>>> import keyword

>>> keyword.kwlist

[‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’, ‘async’, ‘await’, ‘break’, ‘cla

ss’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from

‘, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’, ‘or’, ‘pas

s’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]

Conditional Statement

These statements control the execution of a group of statements based on the truth value of an expression, this simply means, there are sometimes you need to run or not run a given code block depending on the several conditions which needs to be met. The creation of a conditional statement in python is made with the “if” keyword and the following general syntax:

if expr0:

    # Run if expr0 is true

    # Your code goes here…

elif expr1:

    # Run if expr1 is true

    # Your code goes here…

elif expr2:

    # Run if expr2 is true

    # Your code goes here…

else:

    # Run if all expressions are false

    # Your code goes here…

# Next statement

Control Flow (Loops)

Loops are structures that let you repeat python over and over. These can also be referred to as formation or arrangements that permit a user to repeat codes over time. Loops in programming come into use when we need to repeatedly execute a block of statements.

if expr0:

    # Run if expr0 is true

    # Your code goes here…

elif expr1:

    # Run if expr1 is true

    # Do something else…

else:

    # Run if all expressions are false

    # Your code goes here…

# Next statement

Lists: are data structures in Python used to store ordered groups of data; this simply means that for a data to be stored in order, the list factor is very important. It can also be described as an ordered collection of items which makes it easy for a set of data. List values are placed in between square brackets[ ], separated b y commas. It is worth noting that the values in a list do not need to be unique in the sense that the same value can be repeated.

Note: Empty lists do not contain any atom of value around the square brackets.

lists

 primes = [2, 3, 5, 7, 11]

print(primes)

empty_list = []

Functions: A function can be described as a collection of statements that performs certain tasks and gives back the result to the caller, it is also possible for a function to perform some specific task without returning anything to the caller. A function simply performs the activity of creating an ability for a user to reuse the same codes which saves the excessive use of memory, and also creates the ability for the codes to be readable. While making use of Python, def keyword is used in creating functions.

Strings: Strings is described as a specific syntax which can be any length or any form of character such as symbols, whitespace, letters, numbers etc. Strings has the ability to automatically create, rearrange, reassemble, disassemble, and reassign blocks of text. Also,have this in mind that a string can also be referred to as a list of characters, unlike any other list, every character in a string has an Index.

Dictionary : This can be defined as a book or electronic resource that lists the words of a language (typically in alphabetical order) and gives their meaning, or gives the equivalent words in a different language, often also providing information about pronunciation, origin, and usage.

In Python, a dictionary is described as an unordered set of keys that provides us with a technique of mapping out pieces of data to one another in order to easily get the values associated with each other. 

Value in a Python dictionary can be accessed with the process of placing the key within square brackets which are relatively close to the dictionary, with the help of the assignment operator which is (=). To access a value key with a key that does not exist will cause a definite error called ‘KeyError’. 

Files: One of the uses of a file system in computers is that it helps to store and retrieve data, each file is an individual container of related information. Saving, downloading, installing any kind of files on your computer has automatically created a file on your systems, the Python program in which you edit in a learning environment is described as a file. A python file can be created when a file is opened with the ‘open()’ function. The files can be associated with other nature of file using the ‘with’ and ‘as’ keywords 

You can then print the content of the file object ‘file_object’ with ‘print’

Indentations: Indentations are used to highlight blocks of code, for indentation in Python, whitespace is used. It is worthy to note that all statements to the right with the same distance belong to the same blocks of code. 

# Python program showing

# indentation

site = ‘gfg’

if site == ‘gfg’:

    print(‘Logging on to imagine stem academy…’)

else:

    print(‘retype the URL.’)

print(‘All set !’)

Having gotten the knowledge of these syntaxes, let’s take a look at the 7 Easy Steps on how to learn to Code with Python:

7 Easy Steps on how to learn to Code with Python

We shall be using the PyCharm editor for our illustrations

  1. Open PyCham: The act of creating your first program: Open PyCharm editor, the introductory screen for Pycharm is visible. In order to create a new project, click on “Create new Project”.
  1.  Selecting a location: Choosing a location for the purpose of saving your file or folder is very important, you can also select the location where you want your project to be created. If you wish not to change your location, it is important you change the name to something good, for example changing the name from ‘Untitled’ to ‘Dickson Project’. If you downloaded the pycharm editor it would have been configured or seen by the PyCharm Afterwards, click on the ‘Create’ button
  1. Create a New File; Go towards the ‘FILE’ menu, select ‘NEW’, afterward select ‘Python File’

  1. Name your Project:  following the instructions diligently as shown in step 2, a new pop up appears, type in the name of the file you wish to use; in this tutorial, we shall be using ‘Hello World” after writing this,click on the ‘OK’ button 

  1. Write Code: Type a simple program, let’s say print (‘Hello World’)

Indentations: Indentations are used to highlight blocks of code, for indentation in Python, whitespace is used. It is worth noting that all statements to the right with the same distance belong to the same blocks of code.

  1. Run Code: Move towards the direction of the ‘run’ menu, select ‘Run’ for the purpose of running your program 
  1. Code Output: The output of your program is shown/revealed at the bottom of the screen 

Bravo!!!, you have successfully learned how to write your first line of code with Python. These 7 simple steps on how to learn to code with Python will help you get started; 

if you do not have PyCharm, you can make use of any IDE or editor as well.

Looking to start your journey as a programmer join other kids at the Academy today.

Click the button below to start with a FREE online Coding session with an instructor to guide you.