Basic Data Types of Python 3

Shruthi Shantharaju
4 min readAug 28, 2020

--

What is a Data type?

Data type is a keyword which identifies the type of the data stored in a variable.Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

type() function is used in python to retrieve the data type of the value.

The data types in Python are divided in two categories:

  1. Immutable data types — Values cannot be changed.
  2. Mutable data types — Values can be changed.

Numeric Data type :

  1. Int, or integer, is a whole number, positive or negative, without decimals, of any length.
  2. Float, or “floating point number” is a number, positive or negative, containing one or more decimals.
  3. Complex numbers are of the form a + bJ, where a and b holds a numeric value and J (or j) represents the square root of -1 (which is an imaginary number). The real part of the number is a, and the imaginary part is b.

Sequence Data Types:

Each element of a sequence is assigned a number — its position or index. The first index is zero, the second index is one, and so forth.

Strings

The string can be defined as the sequence of characters represented in the quotation marks. In Python, we can use single, double, or triple quotes to define a string. Indexing is used to get the characters in a string.

Lists

A list is a collection which is ordered and mutable(changeable). Creating a list is as simple as putting different comma-separated values between square brackets.

For example −

Tuples

A tuple is a collection which is ordered and immutable(unchangeable). Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.

For example −

Dictionary:

An unordered collection of key-value pairs.Dictionaries are defined within braces {} with each item being a pair in the form key:value. Key and value can be of any type.Access the items of a dictionary by referring to its key name, inside square.

For example −

Sets:

Sets are unordered collection of unique elements and are mutable. Set is created by using a built-in function set(), or a sequence of elements is passed in the curly braces and separated by the comma.

Boolean:

Boolean type provides two built-in values, True and False. These values are used to determine the given statement true or false. It denotes by the class bool. True can be represented by any non-zero value whereas false can be represented by the 0 or empty.

I hope this blog was helpful, thanks for going through this blog.

--

--