How to remove '#' comments from a string?
问题 The problem: Implement a Python function called stripComments(code) where code is a parameter that takes a string containing the Python code. The function stripComments() returns the code with all comments removed. I have: def stripComments(code): code = str(code) for line in code: comments = [word[1:] for word in code.split() if word[0] == '#'] del(comments) stripComments(code) I'm not sure how to specifically tell python to search through each line of the string and when it finds a hashtag,