Data Types

In Python, each character is a specific type of data. Generally, there are 3 data types. The 3 main data types are below:

(1) Strings - Anything inside the apostrophe or the quotation mark is considered a string. No mathematical operation can be performed without a string. Strings are not only letters; even numbers can be strings. For example: '5' is a string, '4243' is a string, 'afwf' is a string. [Written as str].

(2) Integers - All the numbers are considered integers: 5 is an integer, 4243 is an integer, etc. Now, notice that for integers, there are no apostrophes or quotation marks; as such, it is not called as a string. [Written as int].

(3) Floats - Floats are also numbers, but they are decimal values. [Written as float].

If you are confused about the type of data, there is a function in Python which tells you the data type of the character entered. This function is called type()

One data type can be converted to another data type, but there are some restrictions. In order to make this conversion, we will need to specify the data type we want to convert a character into, and then specify the character in parentheses. Examples are provided below:

A string with letters and other characters can not be converted to integers/floats.