evaluating a string
Matthew Dixon Cowles
matt at mondoinfo.com
Tue Oct 17 01:00:00 EDT 2000
More information about the Python-list mailing list
Tue Oct 17 01:00:00 EDT 2000
- Previous message (by thread): evaluating a string
- Next message (by thread): evaluating a string
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 17 Oct 2000 04:01:24 GMT, prakash.ojha at hope.edu <prakash.ojha at hope.edu> wrote: >I am new to Python and would like to know how can I evaluate a string >like "1+2*3/4" to give a numeric result. Is there any built in >function that will give me this result. Any help would be greatly >appreciated. Since this is Python, the answer won't surprise you: the builtin eval() will do what you want: >>> eval("1+2*3/4") 2 Anticipating what may be your next question, the reason that it doesn't give you 2.5 is that in Python, division of integers produces an integer result. Regards, Matt
- Previous message (by thread): evaluating a string
- Next message (by thread): evaluating a string
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list