DEV Community

Cover image for Python 101: The Ultimate Python Tutorial For Beginners.
Kibet Benard
Kibet Benard

Posted on

Python 101: The Ultimate Python Tutorial For Beginners.

Image description

History of Python

Python programming language was created in 1980s by Guido van Rossum at The Netherlands as inspired by ABC programming language and SETL. Ever since the popularity of Python as a choice of language as soared highly and is today ranked as No. 1 by most reputable rankings. This is attributed to the fact that Python is easy to learn and its application areas are wide. Python truely is a beginners dream language.

Application Areas Of Python

Python has gain popularity stemming from the fact that the application are almost limitless. The following are examples of fields where Python are used:

  1. Automation: writing shell scripts to automate everyday repetitive tasks by system admins.
  2. Data Analysis: Owing to its rich libraries and functions in areas of mathematics and statistics, Python has been hugely embraced by the Data science communities.
  3. Web Development: Frameworks like Django and Flask provide the perfect tools for web developers to design beautiful and functional websites and web applications.
  4. Machine Learning: this is the newest area of application of Python which is rapidly growing. Pytorch and Tensorflow are the most important

Getting Started

Installation Guide

Now let's dive right in on how to get Python working in your PC, Linux or Mac.

Installing Python

The latest version of Python at the time of publihing blog is 3.10.4. and this is how to get in your local development environment.

For Linux and Mac Users, the operating systems comes with an installation of Python by default whereas in Windows PCs you have to manually download the Python set up and run it.

Installing on Windows

Follow this link Python 3to download the latest version of interpreter in your development environment.
After running the set up, check if the installation was succesfull by running the following in your favourite command line interface.

python3 -V
Enter fullscreen mode Exit fullscreen mode

Note: When installing on Windows, make sure to check the box indicating to "Add Python 3.x to PATH" so that the interpreter is avialable system wide.

Installation on Mac OS

In order to Install the latest Python interprter, first install Xcode from the AppStore by running the following command from the command line interface.

xcode-select --install
Enter fullscreen mode Exit fullscreen mode

It is advisable to install Homebrew environment by following the guide here . After succesfully installing Homebrew, run the following Brew command:

> brew update
> brew install python3
Enter fullscreen mode Exit fullscreen mode

Installing on Linux

In Order to install Python Interpreter on Linux use the following commands:

sudo apt install python3 #For Debian and Ubuntu Distros
Enter fullscreen mode Exit fullscreen mode
sudo yum install python3 # RedHat and CentOS Distros
Enter fullscreen mode Exit fullscreen mode

Python Devlopment Environment.

A Python programmer can utilize both command line interface or the use of intergrated development environment.
To run Python cli, go to your favorite terminal and
type python3, on pressing enter you will be directed to the interpreted as indicated by >>>
you can run python code in this console. To exit the interface type exit().

Alternatively, and most importantly you can run the Python code from an IDE. Some of the highly recommended IDEs are:

  • VS Code To install VS Code in your operating system follow the following guide:
  • PyCharm Installation guide for Pycharm is found here.

Concise guide to Python Syntax and Elements with Examples

Note: All python code files are saved with .py extension names.

Python programming language is known for its clean and simple syntax. i.e. this is the Python's Hello World code.
print("Hello World!") #write the line and save as helloworld.py
As you can note from the line of code, Python do not use semi-colons at the end of each line of code.

Variables

Variables are used to store and pass values in a program. Variables in Python are not strongly typed meaning the type of value stored by a variables can dynamically change throughout the program execution.

The acceptable ways to name a variable are that the variable names are case sensitive, i.e. 'First' and 'first' variable names are different and store different values.
Value assignment to a variable is done by the use of equals signs.

First='Naomie'
first='Ruth'
Enter fullscreen mode Exit fullscreen mode

Variable Types

The following lines of code depict the different variable types in Python programming.

my_bool = True #Boolean
my_int = 12    #Integer
my_string ="Name"  #String
my_float = 14.85    #Float
my_complex_number = 56+4j #Complex Numbers
my_list = ["mercedes", "redbull", "Hass"] #List
my_dict = {"country" : "France", "worldcups" : 2} #dictionary
Enter fullscreen mode Exit fullscreen mode

Indentation

Unlike other languages which uses curly braces, Python utilizes indentation to define scope and start and end of functions.

def prime_function():
    a=input("Enter the number to test: ")
    print(a)
prime_function()
Enter fullscreen mode Exit fullscreen mode

Comments

Comments in any programming language are important as they make the code readable and easy to debug.
To leave comments on a Python code you use the the # symbol.
print("Hello World!") #This will output Hello World!
Multiline comments are done by using # symbol at the beginning of each line.

Operators In Python

The following are the common operators in Python:

Arithmetic Operators

print(5 + 2) #Addition
print(5 - 2) #Subtraction
print(5 * 2) #Multiplication
print(5 / 2) #Division
print(5 // 2) #Floor Division
print(5 ** 2) #Exponentiation
print(5 % 2) #Modulus
Enter fullscreen mode Exit fullscreen mode

Next Series..

In the next part of the series we will look into more details and intricacies of Python Programming.

Happy Coding. Ciao For now.

Top comments (0)