In the last post, I talked about strings and how to work with them. Today we’ll talk about data type conversion in Python.

To begin with, by default, all entered data is considered as strings. And precisely because of this, adding two lines containing the numbers 2 and 3 in the hope of getting 5 will not work, because i.e. the entered numbers are the default lines – the line addition algorithm will work, and we will get 23:

Especially for solving this problem, you need to convert the data type. For example in int:

As another example of data type conversion, you can specify the conversion of user input to fractional numbers:

The main data types used in Python are:

bool () – accepting value True or False. For example, the result of adding the numbers 2 + 2 = 4 will result in a True value:

while a value of 5 will return False:

There are also a number of other, most commonly used types (each of which we will consider a little later):

dict () – dictionary

list () – list

turple () – tuple

set () – set

abs () – modulus of a number

Would you like to know what type a variable belongs to? Use:

type (), which will output information about the object:

As you can see from the code, the print (type (c)) construct prints the value of the variable with:

<class ‘int’>

Thanks for the support! In case of questions, please write !