-4

I have this string "45/9"

I want to get everything before the slash to be in int1 and get everything after the slash to be in int2.

(Please note: the numbers could grow to triple or even quadruple digits eventually)

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • Does this answer your question? [Split a string by backslash](https://stackoverflow.com/questions/26605076/split-a-string-by-backslash) – David Silveiro Aug 09 '20 at 18:03
  • 2
    Does this answer your question? [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) – bad_coder Aug 10 '20 at 01:00
  • Read about Python fundamentals and most common functions available. Your question can be easily solved using `split` function. This is why you're getting so many downvotes as you don't seem to have done your research before posting the question. – TrigonaMinima Aug 10 '20 at 05:19
  • 1
    Does this answer your question? [Python split string into multiple string](https://stackoverflow.com/questions/9703512/python-split-string-into-multiple-string) – TrigonaMinima Aug 10 '20 at 05:21

3 Answers3

0

Just use string split

s = "45/9"
# split
[int1, int2] = s.split("/")
# convert from string to int
int1 = int(int1)
int2 = int(int2)
frozen
  • 2,114
  • 14
  • 33
0
number = "45/9"
number1 = int(number.split('/')[0])
number2 = int(number.split('/')[1])
ghost
  • 1,107
  • 3
  • 12
  • 31
0
s = "45/9"

int1 , int2 = list(map(int, s.split("/")))

done. string split function splits the string at '/' character and returns a list. map function maps integer to each element of the returned list and returns map object. then used list constructor to create list and int1, int2 variable takes 1st and 2nd value.

DarkCoder
  • 93
  • 1
  • 11