Guide to Basic Data Types in Python with Examples

python_tutorials

Introduction to Python Data Types

In this article, we’ll be diving into the Basic Data Types in Python. These form some of the fundamental ways you can represent data.

One way to categorize these basic data types is in one of four groups:

  • Numeric: int, float and the less frequently encountered complex
  • Sequence: str (string), list and tuple
  • Boolean: (True or False)
  • Dictionary: dict(dictionary) data type, consisting of (key, value) pairs

It’s important to point out that Python usually doesn’t require you to specify what data type you are using and will assign a data type to your variable based on what it thinks you meant.

An equally important thing to point out is that Python is a “loosely/weakly typed” programming language, meaning that a variable can change its type over the course of the program’s execution, which isn’t the case with “strongly typed” programming languages (such as Java or C++).

So something that was an int can end up being a str easily, if you assign it a string value.

In our examples we will occasionally use a function called type(variable) which returns, well, the type of the variable we passed to it.

We will also be

To finish reading, please visit source site