Guest User

Untitled

a guest
Apr 30th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. How can I remove the single quotes from a string and use it for division in Python?
  2. a='/'
  3. b=6
  4. c=3
  5.  
  6. bac
  7.  
  8. a = "/"
  9. b = "6"
  10. c = "3"
  11. print eval(b + a + c)
  12.  
  13. import operator
  14.  
  15. a = operator.div
  16. b = 6
  17. c = 3
  18.  
  19. print a(b, c)
  20.  
  21. ops = {
  22. "/": operator.div,
  23. "*": operator.mul,
  24. # et cetera
  25. }
  26.  
  27. a = ops["/"]
  28.  
  29. >>> a='/'
  30. >>> b=6
  31. >>> c=3
  32. >>> bac = ''.join(str(x) for x in (b, a, c))
  33. >>> bac
  34. '6/3'
  35.  
  36. >>> eval(bac)
  37. 2
Advertisement
Add Comment
Please, Sign In to add comment