In this tutorial we will learn about the different Datatypes in Python and some important facts about them.

A data type, in programming, is a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error.

A string, for example, is a data type that is used to classify text and an integer is a data type used to classify whole numbers.

Any number you enter in Python will be interpreted as a number; you are not required to declare what kind of data type you are entering. Python will consider any number written without decimals as an integer(as in 138) and any number written with decimals as a float (as in 138.0).

- Int
- Float
- Complex

Like in math, integers in computer programming are whole numbers that can be positive, negative, or 0 (…, -1, 0, 1, …). An integer can also be known as an int. As with other programming languages, you should not use commas in numbers of four digits or more, so when you write 1,000 in your program, write it as 1000.

We can print out an integer in a simple way like this:

Or, we can declare a variable, which in this case is essentially a symbol of the number we are using or manipulating, like so:

We can do math with integers in Python, too:

Integers can be used in many ways within Python programs, and as you continue to learn more about the language you will have a lot of opportunities to work with integers and understand more about this data type.

- Python also supports floating-point real values.
- Float values are specified with a decimal point.
- So 2.5,3.14.6.8 etc are all examples of float data type.
- Just like double data types of other languages like java/c, float in Python has a precision of 16 digits.

Some more important facts about float data type:

- For float , we can only assign values in the decimal number system and not in binary, octal or hexadecimal number system.
- Float values can also be represented as exponential values.
- Exponential notation is a scientific notation which is represented using e or E followed by an integer and it means to the power of 10.

- Complex numbers are written in the form, x+yj,where x is the real part and y is the imaginary part.
- For example : 4+5j,12+1j etc.
- The letter j is called unit imaginary number.
- It denotes the value of √-1 , i.e. j ²

Some important points about complex data type:

- For representing the unit imaginary number we are only allowed to use the letter j(both upper and lower case are allowed).
- Any other letter if used will generate errors.
- The letter j, should only appear in suffix, notion prefix.
- The real and imaginary parts are allowed to be integers as well as floats.
- The real part can be specified in any int form i.e.decimal,binary,octal or hexadecimal but the imaginary part should only be in decimal form.
- We can display real and imaginary parts separately by using the attributes of complex types called “real” and “imag”.
- Don’t think real and imag are functions ,rather they are attributes/properties of complex data types.

String is a sequence of Unicode characters. We can use single quotes or double quotes to represent strings. Multi-line strings can be denoted using triple quotes, ''' or """ .Python does not have a char data type , unlike C/C++ or Java. Unlike C language , Pyhton does not uses ASCII number system for character.It uses UNICODE number system.UNICODE is a number system which supports wider range of character compared to ASCII. As far as Python is concerned, it uses UNICODE supports 655536 characters with their numeric values ranging from 0 yo 65535 which covers almost every spoken language in the world like English,Greek,Germen,Korean,Chinese etc.

Whenever we display a string value directly on python's shell i.e. without using the functio print(), python's shell automatically encloses it in single quotes.

However this does not happen when we use print() function to print a string value

If a string with double quotes , it must end with **double quotes ** only.

Similarly if it starts with single quotes , it must end with **Single quotes** only.

Otherwise python will generate error.

If the string contains single quotes in between then it must be enclosed in double quotes and vice versa.

For example:

To print CodeMistic Python Tutorials we would write:

` msg="CodeMistic Python Tutorials"`

Similarly to print Capital of "MP" is "Bhopal", we would write:`msg='Capital of "MP" is "Bhopal"'`

Just like a list and tuple, the slicing operator [ ] can be used with strings.Strings, however, are immutable.

List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type.

Declaring a list is pretty straight forward. Items separated by commas are enclosed within brackets [ ] .

`a = [1, 2.2, 'python']`

We can use the slicing operator [ ] to extract an item or a range of items from a list. The index starts from 0 in Python.

Tuple is an ordered sequence of items the same as a list. The only difference is that tuples are immutable. Tuples once created cannot be
modified.

Tuples are used to write-protect data and are usually faster than lists as they cannot change dynamically.

It is defined within parentheses () where items are separated by commas.

`t = (5,'program', 1+3j)`

We can use the slicing operator [] to extract items but we cannot change its value.

- In python , to represent boolean values we have bool data type.
- The bool data type can be one of two values, either true or false .
- We use Booleans in programming to make comparisons and to control the flow of the program.

Some important points about data type:

Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { } . Items in a set are not ordered.

We can perform set operations like union, intersection on two sets. Sets have unique values. They eliminate duplicates.

Since set are unordered collection, indexing has no meaning. Hence, the slicing operator [] does not work.

Dictionary is an unordered collection of key-value pairs.

It is generally used when we have a huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to retrieve the value.

In Python, dictionaries are defined within braces {} with each item being a pair in the form key:value . Key and value can be of any type.

We use a key to retrieve the respective value. But not the other way around.