# Python Data Types

Vipin | Sun, 07 Jun, 2020 | 188

In Python Data types can be broadly categorized into five different types, listed as follows:

• Numbers
• String
• Tuples
• List
• Dictionary

## Numeric data types or numbers

There are generally four numeric data types in Python. They areintegers, long integers, floating point numbers, and complex numbers

### Integers and long integers

• Integers include zero, all of the positive whole numbers, and all of the negative whole numbers.
• The int or integer data type ranges from -231 to (231-1); the leading minus sign shows the negative values. Beyond these ranges, the interpreter will add L to indicate a long integers.

Example

``````a = 10
b = 30
c = 40``````

### Floating point numbers

Numbers with certain places after the decimal point are referred to as floating point numbers in the programming language:

• The floating point number type ranges approximately from -10308 to 10308 and has 16 digits of precision.
• There are two ways to write a floating point number. It can be written using ordinary decimal notation or scientific notation. Scientific notation is often useful for mentioning very large numbers.

Example

``````a = 20.45
b = 45.099
c = 767.88788``````

### Complex numbers

A complex number has both real and imaginary parts, and Python allows you to specify this data type in a very easy and convenient way.

Syntax:

<variable_name> = complex(x,y)

OR

<variable_name> =x+yj

Here, x is the real part and y is the imaginary part. Here, j plays the role of iota.

Example

``````num = complex(3,5)

# or

num = 3+5j``````

### Boolean data type

A Boolean data type generally has only two values 'True' or 'False'.

Boolean data type is a sub type of integers.

Syntax:

<variable_name> = <'True' or 'False'>

Example

``````a = True

b = False``````

Boolean data types can be referred to as an on and off switch, which has only two values to chose from.

### String data types

A Python string is a contiguous sequence of Unicode characters.

Single quotes or double quotes can be used to denote a string. For multiline string representation, ''' or "' can be used.

### Syntax:

<variable_name> = <String Sequence>

Example

``````my_str1 = "HelloWorld"

my_str2 = 'Selfcode.in'

my_str3 = '''
This is multiline String
'''
``````

0 comments