Python Variables and Data Types

A Variable is a named location that is used to store data in memory. Variables are like containers that store data that can be changed later according to the needs of the program. Each and every value in Python has a Data Type.

Why use variables?

We can assign a value, a character, and a string to a variable. Variables store the values which are to be referenced and can be manipulated in a computer program. The sole purpose of variables is to label and store data in memory and this stored data can be used throughout a program.

Assigning Variables

To assign a value to a variable we use the (=)  sign. This is an Assignment Operator.

So let's understand this with the help of an example.

So in the above code, I had used 3 variables (name, age, marks) and I had assigned the values to each variable respectively in their specific data type. After assigning the values I just used the print statement to get the output.

We can also assign a single value to multiple variables and this process is known as multiple assignments. Here is an example of multiple assignments.

So moving on to our next part which is Data Types In Python.

Why Data Types are important?

Like all other programming languages, Data Types are also used in the Python Programming language to classify one particular type of data. This is important because the specific Data Type we use will determine what values we can assign to it and what operations we can perform on it.

Standard Data Types of Python

Python has five standard data types -

  1. Numbers
  2. String
  3. List
  4. Tuple
  5. Dictionary

Numbers

Integers, Floating point numbers, and complex numbers fall under the category of Python Numbers and these are defined by (int, float, complex) respectively.

Integers can be of any length, it is only limited by the memory available.

A floating-point number is accurate up to 15 decimal points.

Complex numbers are written in the form of a + bj where a is the real part and b is the imaginary part.

String

The string is a sequence of Unicode characters. A string is basically written in Single Quotation marks or in double quotation marks.

In the above code, we had assigned some data to variable (a) in the form of a string.

Lists

Lists are used to store multiple items in a single variable. the list is an ordered sequence of items. The list is a built-in data type. A-List is always written in square brackets[ ].

Here is a list.

Tuple

A tuple is also an ordered sequence of items similar to a list but tuples are immutable in nature. Tuples are also built-in data types like Lists. Once created tuples cannot be modified. A tuple is always written in Parenthesis( ).

Here is a tuple.

Dictionary

Unlike List and Tuple, Dictionary is an unordered collection of key-value pairs. The pair is in the form of a key: value. It is also a built-in data type just like both Lists and Tuples. We use Dictionary when we have a huge amount of data. These are used for retrieving data. A dictionary is represented with curly brackets{ }.

Here is a dictionary.

For more help regarding this topic, visit my channel and start learning python from basics and become a python coder. For amazing posts, quizzes and memes follow us on Instagram.

Enjoy learning. Thanks for reading. Stay tuned with us and also subscribe to our newsletter.

NOTE:- The awesome artwork used in this article was created by Learning Tech

HAPPY NEW YEAR

Get the latest episodes directly in your inbox