From e2e8e42d52539d1320ac3239181193792bdba174 Mon Sep 17 00:00:00 2001 From: Satwik Kansal Date: Wed, 17 Jan 2018 19:23:13 +0530 Subject: [PATCH] Update backslash example --- README.md | 24 +++++++++++++++++++----- parse_readme.py | 31 ------------------------------- 2 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 parse_readme.py diff --git a/README.md b/README.md index c275447..6732410 100755 --- a/README.md +++ b/README.md @@ -407,19 +407,25 @@ Can you guess why the output is `[2, 4]`? **Output:** ``` ->>> print("\\ some string \\") ->>> print(r"\ some string") ->>> print(r"\ some string \") +>>> print("\\ C:\\") +\ C:\ +>>> print(r"\ C:") +\ C: +>>> print(r"\ C:\") File "", line 1 - print(r"\ some string \") - ^ + print(r"\ C:\") + ^ SyntaxError: EOL while scanning string literal ``` #### 💡 Explanation - In a raw string literal, as indicated by the prefix `r`, the backslash doesn't have the special meaning. + ```py + >>> print(repr(r"wt\"f")) + 'wt\\"f' + ``` - What the interpreter actually does, though, is simply change the behavior of backslashes, so they pass themselves and the following character through. That's why backslashes don't work at the end of a raw string. --- @@ -1546,6 +1552,14 @@ another_dict[1.0] = "Python" "Python" ``` +3\. +```py +>>> some_bool = True +>>> "wtf"*some_bool +'wtf' +>>> "wtf"*some_bool +'' +``` #### 💡 Explanation: diff --git a/parse_readme.py b/parse_readme.py deleted file mode 100644 index b8690ef..0000000 --- a/parse_readme.py +++ /dev/null @@ -1,31 +0,0 @@ -import pprint - -fname = "README.md" -snipepts = [] - -with open(fname, 'r') as f: - lines = f.readlines() - for line in lines: - # check if it's a H3 - if line.startswith("###"): - title = line.replace("### ", "") - # get Title, des - # store lines till an H4 (explanation) is encountered - # store lines again until --- or another H3 is encountered - snippets.append({ - "title":, - "description":, - "explanation": - }) - # repeat until EOL is encoutered - -# separating by category -categories = ["a", "b", "c"] - -snips_by_cat = {k:[] for k in categories} - -for snip in snippets: - cat = raw_input(snip["title"]) - snips_by_cat[cat].append(snip) - -pprint.pprint(snips_by_cat)