YagizWasTaken
YagizWasTaken

Reputation: 23

Python how can I make an int to a string?

import keyboard
import time

s1 = 1
time.sleep(1)
while s1 < 100:
    keyboard.write(s1)
    s1 = s1 + 1

I can't write s1 because 1 is an int. But if I make it s1 = "1" then I can't do s1 < 100 because s1 is a string, so I need to write s1, but how?

Upvotes: 0

Views: 112

Answers (2)

Aza
Aza

Reputation: 17

I think this is what you're trying to do here. I also changed the last line as it's simpler like that

import keyboard
import time

s1 = 1
time.sleep(1)
while s1 < 100:
    keyboard.write(str(s1))
    s1 += 1

Upvotes: 0

Liam Welsh
Liam Welsh

Reputation: 314

You can use the int() or str() function where you need the value to be a string or int without reassigning it.

import keyboard
import time

s1=1
time.sleep(1)
while s1<100:
    keyboard.write(str(s1))
    s1=s1+1

Upvotes: 2

Related Questions