0
time = raw_input()
if "PM" in time:
    ls = time.split(":")
    int(ls[0])
    print type(ls[0])

I have a problem on Hackerearth which I was solving. But my code here doesn't change the str to int. The output is

<type 'str'>

I want to change the first element of the time to int so i can perform mathematical calculations on it. Input it takes is

6:05:08PM

3 Answers 3

1

int() returns the integer. The variable is not changed in-place.

Assign the result:

ls[0] = int(ls[0])
Sign up to request clarification or add additional context in comments.

Comments

0
Integer = int(ls[0])

It cast str to an int and then u can use this Integer to do calculations

Comments

0

int(ls[0]) should do the trick for you, however, note that this is a very less safe approach.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.