Datatypes In Python

1. Numbers:

Numbers are used to represent quantities in Python.

  • Integer (int): Whole numbers without any decimal points.

      age = 10
    
  • Float (float): Numbers with decimal points.

       height = 4.5 data type in Python represents complex numbers, which consist of a real part and an imaginary part.
    
    • complex: complex number is written in the form a + bi, where:
  • a is the real part,

  • b is the imaginary part, and

  • i is the imaginary unit, which represents the square root of -1.

In Python, you can create a complex number using the complex() function. For example:

    z = complex(2, 3)

2. Strings:

Strings are used to represent text in Python. They are enclosed in single (' ') or double (" ") quotes.

name = 'techvito'

3. Lists:

Lists are used to store multiple items in a single variable. They are ordered and mutable (changeable).

colors = ['red', 'blue', 'green']

4. Tuples:

Tuples are similar to lists but are immutable (cannot be changed after creation). They are enclosed in parentheses.

coordinates = (3, 4)

5. Booleans:

Booleans represent truth values. They can only be True or False.

is_raining = True

Example:

Here's an example using multiple data types:

name = 'guido'
age = 48
height = 5.5
likes_ice_cream = True
favorite_colors = ['red', 'blue']

In this example:

  • name is a string.

  • age is an integer.

  • height is a float.

  • likes_ice_cream is a boolean.

  • favorite_colors is a list containing strings.

Data TypeDescriptionExample
IntegerWhole numbers without decimal pointsage = 10
FloatNumbers with decimal pointsheight = 4.5
StringText enclosed in single or double quotesname = 'techvito'
ListOrdered collection of itemscolors = ['red', 'blue']
TupleImmutable ordered collection of itemscoordinates = (3, 4)
BooleanRepresents truth values (True or False)is_raining = True