I need to convert a string into an int type, so i can perform my operation
>>> t="'2000'"
>>> int(t)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: "'1'"
You have a double quoted string, in the error message it warns you about thr ' beeing a illegal number for conversion. Either clean your string to t="10" removing the redundant quotes or strip the string if received from else where int(t[1:-1]).
'2000' with t="'2000" as a result, so you want to omit the first and the last character of the string, leaving it as 2000. In python you can slice a string by taking a range of the string (by the braces []) with a from-to range as from character to character (i.e. [1:5] giving the secound to the sixt char of a string), you can also reverse index with -1 being the last char in the string, so t[1:-1] gives you all the string but the first and last char and converts the rest to string ^^You're trying to parse the string '2000' into an int, which it is not since there are quotes around the 2000. You can change the code to this to make it work:
t = "'2000'"
t = t[1:-1]
int(t)
int(t[1:-1]) with t being t = "'2000'" and it will work aswell.int(t[1:-1])
int("'2000'".strip("'")should do it."TAT".strip("T")returns "A" - all the given characters to strip are removed from start and end of string