DEV Community

Cover image for INTRODUCTION TO MODERN PYTHON: BASICS
Kouti Divine
Kouti Divine

Posted on

INTRODUCTION TO MODERN PYTHON: BASICS

By the end of this article you would learn the following;

  • What is python, its origin and its application.

  • The advantages of python as compared to other languages.

  • Explain with examples the use of data types and
    variables.

  • Explain the use of functions and methods in python.

  • Explain basic control flow if/else statements.

WHAT IS PYTHON

Nowadays PYTHON is one of the most popular programming languages(PL).

Definition
Python is an interpreted high level, general purpose programming language. Its design philosophy emphasis code readabilaty with use of indentation.

ORIGIN

The PL PYTHON was designed in the late 1980`s by GUIDO VAN ROSSUM. It was first released in 1991 as PYTHON 0.9.0. for the past years different versions of python have been released and the newest version was released in 2020 which is python 3.9.


FIELDS OF APLICCATION OF PYTHON
Since PYTHON is a general purpose PL it can be used in many fields like;
  • AI and Machine learning

  • Data analytics

  • Data visualisation

  • Web development

  • Game development

  • Finance.
    Advantages of python as compared to other languages.

  • Python is a user friendly PL.

  • Taking a PL like C we notice that python takes less lines so as
    to perform a certain task.
    IN PYTHON.
    Image description
    IN C.

Image description

  • Also comparing python with javascript, python can be used both as a scripting language and also as a programming language whereas javascript is only a scripting language.

Getting started with python programming.

INSTALLING PYTHON

You can get the link here

Once installed you can get the version of python installed by opening the cmd(comand prompt) in windows or the terminal in UNIX and then type python --version

Also there are different IDE`s one can use such as VScode, Anaconda, Spyder, Pycharm just to name a few.

Now that we are done with the installation let us dive into coding.
In order to begin with any programming language we need to first look at the basics.

Variables and Data types

Variables
A Variable is a storage location paired with an associated symbolic name, which contains some known or unknown quantity of information refered to as value.

it can be a word or a sentence or even a letter but not a number depending on the programer that is used to store a known or an unknown value..

`gender=" female"
 name='DIVINE'`
Enter fullscreen mode Exit fullscreen mode

from the above gender and name are variables.
Rules for naming variables.

  1. you should not start a variable with numbers.
    EXAMPLE
    19gender is a wrong variable.

  2. special characters like $,!, /, \, # should not be added to your variable.

  3. your variable name should not be seperated. We only seperate variables using an underscore(_).
    EXAMPLE
    choir_singer

  4. In python variables are case sensitive..
    Data types
    They include;
    Numerical data type
    Strings
    List
    Tuples
    Sets
    Dictionary
    Range.

You can learn more about each of these data types here

functions and methods
FUNCTIONS
A function is a block of code that runs when it is called.
a function is defined with the def keyword.
Layout.
Image description
Learn more about functions here
Methods
n Object-Oriented Programming, we have objects. These objects have both properties and behavior. Morover, properties of the object are defined by the attributes and the behavior is defined using methods.
we have 3 types of methods which are

  • Instance Method

  • Class Method

  • Static Method
    Learn more about methodshere

Basic control flow and if/else statements
In python, control flow or flow control statements refers to the order in which a code is being executed.
They inchude:while, for, if.
Also control is regulated by conditional statements, loops and function calls.

Image description
Simple if/else statement.
Decision making is required when we want to execute a code only if a certain condition is satisfied.

Layout


`if condition:
    code
else:
    code `
Enter fullscreen mode Exit fullscreen mode

FLOWCHART

Image descriptionlearn more about control flow statements here..
THANK YOU FOR READING

Top comments (0)