Python Logic Building for Beginners | Python Programming Tutorial 2026

Akansha Yadav shows how to convert a string like "123456" into a Decimal object using Python's decimal library. She imports the module, calls Decimal(string), then adds numbers to it to prove the conversion works. The tutorial explains that arithmetic only works on numeric values, not character strings.
Chapters
Now let us see how we can convert any string into decimal. So we are going to do one data type conversion into another, but we are going to work on string of integer. It means any numerical value but in the format of string. So we are going to use a decimal library from Python. I am going to create one variable string in which I am storing 1, 2, 3, 4, 5. Then I am writing print decimal decimal which is a function in the decimal library, and passing a value string to get it done. Then I am going to do some addition on top of the number which is generated. So basically we can, we can perform any mathematical operation on the number, on the numerical value. So I am trying to add 1, and then I am going to cross-verify whether the conversion is done or not. So this is my entire code. Let's execute it. So initially I stored 1, 2, 3, 4, 5, 6. But when I added 1 in the integer, when I did the conversion from the string to decimal, I added 1. So it becomes 123457. And then we can also see the decimal, uh, is the data type. When I'm trying to add 100, it is 456 earlier, but when I added 100, it is 556. It means we are able to do the addition also on the number generated. It is very simple to do the conversion. So we are using the decimal library. Libraries are nothing but just a file in Python which has all the things for you. Now I have created a string variable and 123456 is the value. Then decimal is with the d in the lowercase, is the name of the library. You have to write it exactly same. Then .decimal, it means D capital. This is the full function which is in the library. Then I am passing a parameter. Within the function. It is string. So string is what? String is a function parameter. Now once we are done declaring anything, you can even use it, you can store it in the variable as well. Then you can— you are going to perform plus. It means that is an arithmetic operation which works only on numeric value. You cannot do addition or anything on characters, words, or sentences. So I'm adding 100 and using the type function to Check what is the data type of the string variable because I have made all the changes in the string variable directly.










