Jan-08-2018, 10:12 PM
(Jan-08-2018, 09:49 PM)Truman Wrote: If I add 'book' in the first variable and 'notebook' in the second it will give True although book and notebook are different things. The reason is that last 4 characters in 'notebook' match with 'book'.
In order to get around that, you should split the string into a list of available options. The
in
operator can still be used at that point.>>> can_read = "book" >>> things = "website, blog, book" >>> can_read_things = things.split(", ") >>> can_read_things ['website', 'blog', 'book'] >>> can_read in can_read_things True >>> things = "website, blog, notebook" >>> can_read_things = things.split(", ") >>> can_read in can_read_things False