- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to 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
- Related Articles
- Add two numbers represented by two arrays in C Program
- Multiply Large Numbers represented as Strings in C++
- Program to find numbers represented as linked lists in Python
- Python program to add two numbers
- Add two numbers represented by linked lists?
- Why are numbers represented as objects in python?
- Program to add two binary strings in C++
- Java Program to Add Two Binary Strings
- Program to add two binary strings, and return also as binary string in C++
- C++ Program to Add Two Numbers
- Java Program to Add Two Numbers
- Kotlin Program to Add two Numbers
- Add Two Numbers in Python
- Program to expand string represented as n(t) format in Python
- Program to Add Two Complex Numbers in C

Advertisements