Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string error
#2
true division always returns float, so length / 2 returns float which is not allowed as index. use floor division length // 2

also don't use str as variable name . it's a type and you overshadow it, i.e. you will not be able ti use it if needed

my_str = 'foo'
print(isinstance(my_str, str))
str = 'bar'
print(isinstance(my_str, str))
Output:
True <-- this is first print Traceback (most recent call last): File "************", line 4, in <module> print(isinstance(my_str, str)) TypeError: isinstance() arg 2 must be a type or tuple of types
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
string error - by satyam - Aug-11-2018, 05:00 PM
RE: string error - by buran - Aug-11-2018, 05:18 PM
RE: string error - by satyam - Aug-12-2018, 04:19 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020