Python Data Type

tags: #python/intro

What is a data type?

Data types specify the type of data that is stored inside a variable.

Common Data Types in Python

Python consists of several built-in data types and structures:

Data Types Description
Numeric holds numeric values (int, float, complex)
String holds sequence of characters (str)
Collection holds collection of items or elements (list, tuples, dictionary, set). They can also be referred to as data structures.
Boolean holds either True or False
Each data type has its own set of properties, methods, and behaviours.
Atomic Data Types

int and float are considered to be simple or primitive or atomic data types because their values are not composed of any smaller parts.

Numeric Data Type

Python numeric data types store numeric values. Numeric instances (objects) are created when you assign a numeric value to them.

var1 = 1
var2 = 10
var3 = 10.023

There are three distinct numeric types: integersfloating point numbers, and complex numbers.

String Data Type

Python Strings are identified as a contiguous set of characters or a sequence of characters enclosed in single or double quotation marks.

varstr = "This is a string"
varstr2 = 'This is also a string'

Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end.

Boolean Data Type

Boolean data types represent either True or False, used for logical operations and conditions.

Collection Data Types

Common collection data types in Python include:

Powered by Forestry.md