- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can we do math operation on Python Strings?
You can use the eval function to evaluate mathematical expressions in strings.
For example, if you have a string with the content (4*5) + 21, you can eval it and get the result.
>>> s = "(4*5) + 22" >>> eval(s) 42
Eval follows Python rules for evaluating mathematical expressions for cases in which parenthesis are not provided, etc. Be very careful when using eval though as it can be a source of huge security loopholes and bugs.
- How can we do date and time math in Python?
- How to do Python math at command line?
- How To Do Math With Lists in python ?
- Math Operations on BigInteger in Java
- MongoDB aggregation / math operation to sum score of a specific student
- How can we do Python operator overloading with multiple operands?
- How can we concatenate two strings using jQuery?
- How we can run Python CGI Script on Windows XP?
- How can we do the basic print formatting for Python numbers?
- What does % do to strings in Python?
- Can we use Switch statement with Strings in java?
- 8085 Program to do an operation on two numbers based on the contents of X
- How do we mix two strings and generate another in java?
- Program to count number of strings we can make using grammar rules in Python