Python Forum
multiply all input arguments if int or float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiply all input arguments if int or float
#5
(Nov-03-2016, 07:50 PM)roadrage Wrote: All of the elements in list b are coming up as type str, how to convert them to int or float??

As easily as asking nicely that they be int or float:
>>> x = '534'
>>> type(x)
<class 'str'>
>>> y = int(x)
>>> type(y)
<class 'int'>
>>> z = float(x)
>>> type(z)
<class 'float'>
That said, why are you using ast for anything this simple?  You're not creating blocks of code and traversing the call stack, you're just... multiplying numbers...
Speaking of which, why define a multiply function if you'll never call it?
Reply


Messages In This Thread
RE: multiply all input arguments if int or float - by nilamo - Nov-07-2016, 06:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python!TypeError: can't multiply sequence by non-int of type 'float' shaywune 2 9,603 Sep-24-2016, 04:33 PM
Last Post: shaywune

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020