A Complete Beginner-Level Python Course to Learn Data Science and Machine Learning

Part 1: Data Types and Operators in Python

Muhammad Umair
Python in Plain English

--

This is a complete guide to learn Python, to go from beginner to expert. In this, we will learn all the Python components that are needed to become an ML expert or data scientist.

First of all, we will start with variables.

Day 1: Data Types (Variables) & Operators

Variables

Definition

A characteristic, number, or quantity that increases or decreases over time, or takes different values in different situations.

In simple words, a variable is the named memory location.

Two basic types

  1. Independent variable: that can take different values and can cause corresponding changes in other variables.
  2. Dependent variable: that can take different values only in response to an independent variable.

Purpose

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information.

Importance

Variables play an important role in computer programming because they enable programmers to write flexible programs. Rather than entering data directly into a program, a programmer can use variables to represent the data. The opposite of a variable is a constant. Constants are values that never change.

Application

Variables are used in any computer program. They are very useful as they help to store information such as names, lists, and even complete functions.

They are used in all of the systems such as a “Library Management System”, “Database Management System”, etc.

Strengths

The greatest advantage of variables is that they enable one and the same program to execute various sets of data. In the light of the afore-stated, a variable refers to a symbol for a varying value, which is stored in the system’s memory.

They help us in stopping code repetition and to better manage our code.

If you use variables, you can make your code cleaner and simpler (which would help others, as well as yourself, understand it better). Also, it’s generally a good practice.

Variables are used for storing data, and then you can carry that variable over from one function to another.

Weakness

The biggest weakness of using variables in Python is that if a variable of a string type is defined in a program, and you mistakenly forget that you have already initialized that variable and you save the integer data type in the variable, the property will change and it will become the integer variable instead of string type.

Example 01

Task

Create a variable of string type and save your name inside it. Print the name and show that the data type of the variables in Python can be changed just by assigning a value of a different datatype to the variable.

Code

Name=”Muhammad Umair”
print(Name)
print(type(Name))
Name=5
print(Name)
print(type(Name))

Output

Muhammad Umair
<class 'str'>
5
<class 'int'>

Example 02

Task

Save your personal information into four variables and print their values.

Code

age=20
weight=65.2
name=”Muhammad Umair”
fatherName=”Muhammad Akram”
print(name)
print(age)
print(fatherName)
print(weight)

Output

Muhammad Umair
20
Muhammad Akram
65.2

Operators

Definition

An operator in a programming language is a symbol that tells the compiler or interpreter to perform the specific mathematical, relational, or logical operation and produce the final result.

Purpose

They are used to do many of the basic mathematical computations.

Importance

Operators are very useful in programming as they help us perform so many mathematical computations and also the logical operators such as AND, OR, and NOT help us make decisions on the basis of certain conditions.

Application

There are a number of applications of operators such as the calculator program, a computer program used in the banks to do computing on the money to calculate all the ups and downs in the money, etc.

Strengths

They help us by reducing so much of our work as otherwise, we cannot imagine how much assembly language code we will have to write to simply add two numbers and it would be so difficult to do an AND, OR, NOT function.

Weaknesses

As they are simple math functions, there are not many weaknesses in them. The only weakness they can be said to have is our own grasp of mathematics. As if our own math understanding is wrong, we will end up using the operators wrong too.

Suitable to Use

They are suitable to use in any scenario where you want to use mathematical computations or logical computations.

Example 01

Task

Take four variables of integer type and apply math operations to them.

Code

numberOne=10
numberTwo=20
numberThree=30.5
numberFour=6.7
print(numberOne+numberTwo)
print(numberOne-numberTwo)
print(numberOne+numberThree)
print(numberThree*numberFour)
print(numberOne**2)

Output

30
-10
40.5
204.35
100

That’s it for this introductory part. See you in the next one.

More content at plainenglish.io

--

--

MERN Stack Developer | Software Engineer| Frontend & Backend Developer | Javascript, React JS, Express JS, Node JS, MongoDB, SQL, and Python