+ 1

python 09 + 23

I was dealing with a bunch of data, and I wanted to add the number 09 with another number. Are there any suggestions? e.g. print(09+1)

22nd Aug 2019, 4:02 PM
Batman
Batman - avatar
4 odpowiedzi
+ 1
either int("09") + 23 or "09" + str(23) you can't add a string to an number(int/float)
22nd Aug 2019, 4:17 PM
Anton Böhler
Anton Böhler - avatar
+ 1
A thing to note is... in our mathematics 09 is considered as an Integer but in python its an invalid token itself NO INTEGER IN ITS TRUE FORM CAN CONTAIN 0 AT FIRST so, even print(09) itself will give you error msg
22nd Aug 2019, 9:56 PM
sayan chandra
sayan chandra - avatar
0
perhaps I didn't express it clearly. What I meant is that number 9 must stay in the form of "09" (doesn't matter if it's a int or str), and plus another number: print(09+4) SyntaxError: invalid token
22nd Aug 2019, 4:14 PM
Batman
Batman - avatar
0
Is this what you are are trying to do?:- print('09 + 23 = {}'.format(int('09') + 23)) # or mynum = '09' print(mynum, '+ 23 = {}'.format(int(mynum) + 23))
22nd Aug 2019, 10:27 PM
rodwynnejones
rodwynnejones - avatar