How do I concatenate string and an integer?
Question:
act = input("Enter name of the activity")
cellone = int(input("Enter the order number of activity"))
cell1 = "A" + cellone
worksheet.write(cell1, act)
I’m trying to concatenate A
and cellone
but I’m getting some error saying that I can’t concatenate string and an integer, is there a way to do this?
Answers:
str(cellone)
returns the value of cellone
as a string.
call1="a"+str(cellone)
Remove the int in line 2 as follows:
cellone=input("Enter the order number of activity")
It takes the input as a string data type anyway
Just dont convert the string to int. correct that to
cellone=input("Enter the order number of activity")
You can change int
to a string
representation using this:
cell1="A"+str(cellone)
Alternatively, f-string
formatting will also work:
cell1=f"A{cellone}"
act = input("Enter name of the activity")
cellone = int(input("Enter the order number of activity"))
cell1 = "A" + cellone
worksheet.write(cell1, act)
I’m trying to concatenate A
and cellone
but I’m getting some error saying that I can’t concatenate string and an integer, is there a way to do this?
str(cellone)
returns the value of cellone
as a string.
call1="a"+str(cellone)
Remove the int in line 2 as follows:
cellone=input("Enter the order number of activity")
It takes the input as a string data type anyway
Just dont convert the string to int. correct that to
cellone=input("Enter the order number of activity")
You can change int
to a string
representation using this:
cell1="A"+str(cellone)
Alternatively, f-string
formatting will also work:
cell1=f"A{cellone}"