
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add Two Numbers Represented as Strings in Python
Suppose we have two strings S, and T, these two are representing an integer, we have to add them and find the result in the same string representation.
So, if the input is like "256478921657", "5871257468", then the output will be "262350179125", as 256478921657 + 5871257468 = 262350179125
To solve this, we will follow these steps −
- convert S and T from string to integer
- ret = S + T
- return ret as string
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, a, b): return str(int(a) + int(b)) ob = Solution() print(ob.solve("256478921657", "5871257468"))
Input
"256478921657", "5871257468"
Output
262350179125
Advertisements