DEV Community

Cover image for Python 101: The Ultimate Python Tutorial For Beginners
Pius Kariuki
Pius Kariuki

Posted on

Python 101: The Ultimate Python Tutorial For Beginners

INTRODUCTION

Python is a high-level, general purpose programming language. Designed philosophically emphasizes code readability with the use of significant indentation. Its language construct and object oriented approach aims to help programmers write a clear and logical codes. Python program have an extension .py. It is a general purpose programming language due to range of application such as: Machine Learning & AI, automation, image processing, scientific computing, web development and data base to mention a few.
Python has developed a lot from the first time it was created. It was conceived in late 1990s by Guido Van Rossum as a successor to to ABC programming language. It was first released in 1991 as python 0.9.0, then python 2.0 introducing features like; list comprehension, garbage collection, reference counting and unicode support. Later python 3.0 was released. Python has remained one of the most popular programming language to date as: It is very flexible, increases productivity, supportive community and it is easy to learn.

I have this hope that there is a better way. Higher-level tools that actually let you see the structure of the software more clearly will be of tremendous value, Guido Van Rossum

PYTHON ENVIRONMENT

Setting up Python
Python comes with two main distribution that include: Python Software Foundation(PSF) and Anaconda Distribution.
as with any programming language the first step is to learn how to install it.
Python Installation For windows
step 1: Open any browser on your windows
Step 2: Use the link; https://www.python.org
step 3: click for the latest Python3 release
step 4: Download and Run the executable .exe installer
step 5: Verify python was Installed on windows

Image2

PYTHON IDEs AND CODE EDITORS

Code editors are light weight tools used to write and edit code. However, complex and larger programs need testing and debugging. IDES compared to editors come in handy in such instances. They help you understand your code better than a text editor making it easier to code by allowing you to write, test and debug at the same time. Examples of such environments: Sublime Text 3, Atom, Thonny, Pycharm, Visual Studio Code and vim.
Download any and run the installer like any other program and you are ready to code.
LETS CODE
We will write "Hello, world!" program.
To print out something in python we use the print() function.

#Running our first program

print("Hello, world!")

Enter fullscreen mode Exit fullscreen mode

Before running the code, we need to save it. Save as Hello.py the .py extension tells our interpretor that its running a python code. After saving run the program.

#Output:
Hello, world!
Enter fullscreen mode Exit fullscreen mode

Did you get this? If yes, Kudos! You have executed your first program.

FUNDAMENTALS OF PHYTHON

This are some of the python basic that a beginner ought to understand.

Syntax & Semantics:

Python is meant to be an easily readable language. Its formatting usually uncluttered and often uses English keywords where other languages use punctuations. Such keywords include; and, as, assert, async, await, break, class, def etc.it does not use curly brackets to delimit blocks and semicolons after statements.

Variables:

A variable is used to store data(values) in programming.
For Example,

a = 10
b = 0.5
Enter fullscreen mode Exit fullscreen mode

a and b are variables with values 10 and 0.5 respectively.
Python Literal is a raw data for representing fixed values example, 10 and 0.5 are literals.

Data Types:

Data types make Python programming easier. A data type is a set of values and a set of operations defined on data. Data types in python:
Numeric Types: int, float, complex
Sequence Types: list, tuples,rangs
Set types: frozen, set
Mapping Types: dict.
Boolean Type: bool

Python Comments:

A comment is used to describe what's going on inside a program. they make the code understandable. The Python interpreter ignores such comments. #symbol is used to write a single-line comment.
Other Types comments:
->Multi-line comment
->doc-staring comments

#This is a comment, not executed
a = "Hello World" # a contain "hello world" A string literal 

Enter fullscreen mode Exit fullscreen mode

OPERATORS:

An operator is a special symbol that carries out arithmetic or Logical operations, such multiplication and addition.

a = 10
b = 20
sum = a + b
print(sum)
# Output: 30
Enter fullscreen mode Exit fullscreen mode

Types of operators include:
1: Arithmetic Operators: Perform mathematics operations.
Examples of arithmetic operators: + operator used to sum operands, * operator used to multiply operands, - operator used to subtract operands, / operator used to divide left operand by the right, // operator used to find the quotient, % operator used to used to give the reminder of the division,** operator raises the right operand to the power of the left. Example.

a = 2
b = 5 
result =  a**b # 2 raised to the power of 2
print(results)

#output: 32
Enter fullscreen mode Exit fullscreen mode

= assignment operator.
2: Logic operators: Logic AND, Logic OR and Logic NOT.
3: Comparison Operators: Used to compare two values.

Indentation:

Python relies on indentation, white spaces, to define scope in a code. Other programming languages often use curly-brackets for this purpose.

Loop:

loops are statements used to iterate over an object. Types of loops include: while loops and for loops.
A for loop used to iterate through collection of items.
For Example,

languages = ['Python', 'C++', 'PHP']
for item in languages:
 print(item)

#output: 
Python
C++
PHP
Enter fullscreen mode Exit fullscreen mode

While loop allows you to execute a set of instruction untill the given condition is true.
Example,

i = 3
n = 1
while n <= i:
  print("Python is easy")
  n = n + 1 # n is increased by 1

# output:
Python is easy
Python is easy
Python is easy

Enter fullscreen mode Exit fullscreen mode

Constant:
Constant is a type of variable holds values, whose values cannot be changed. Rarely do we use constants in Python.

CONCLUSION.

This tutorial is meant to help you familiarize with Python programming language. We started with knowing what Python is, installation process, writing our first program and finally some basics fundamentals of Python. There is more than that in Python programming.
Thanks for reading.

Bibliography:
Guido Van Rossum.(n.d.).AZQuotes.com. Retrieved April 23, 2022, from AZQuotes.com Web site: https://www.azquotes.com/author/46455-Guido_van_Rossum
Python(programming language) - Wikipedia: https://en.m.wikipedia.org
Python.Net Tutorial For beginners.
Zen of Python: https://peps.python.org

Top comments (0)