Step Three: Escape!

来源:互联网 发布:现货知乎 编辑:程序博客网 时间:2024/06/03 20:35
Step Three: Escape!

Don't get too comfortable: you can't use justany symbol in a string, and some results can only be achieved by special characters. The practice of including these characters in a string requires that these strings beescaped, or marked as unique. The backslash character (\) does this work for us! We just put it directly before the character we want to escape.

The string in the editor is broken: the apostrophe in I'm makes Python think the single-quote string ends there. Fix it by escaping the ' in I'm!


# The string below is broken. Fix it using the escape backslash!s="Help! Help! I'm being repressed!"print ss='Help! Help! I\'m being repressed!'print s


原创粉丝点击