mystring = '[:3]'
x = mystring.split()
z = str(x).lstrip("['").rstrip("]'")
print(z)
print('hello'+int(z))
错误:ValueError:以10为底的int()的无效文字:':3'
如何通过对'mystring'变量进行切片来使输出为'hel'?
我认为这是您要尝试做的....
mystring = '[:3]'
#x = mystring.split()
z = str(mystring).lstrip("['").rstrip("]'")
print(z)
print('hello'+z)
所以输出是..
:3
hello:3