{"id":4092,"date":"2023-07-11T12:27:49","date_gmt":"2023-07-11T12:27:49","guid":{"rendered":"https:\/\/picockpit.com\/raspberry-pi\/?p=4092"},"modified":"2023-08-11T10:47:40","modified_gmt":"2023-08-11T10:47:40","slug":"9-tricks-with-the-python-repl","status":"publish","type":"post","link":"https:\/\/picockpit.com\/raspberry-pi\/zh\/9%e7%a7%8dpython%e6%9b%bf%e6%8d%a2%e6%8a%80%e5%b7%a7\/","title":{"rendered":"\u4f7f\u7528Python REPL\u76849\u4e2a\u6280\u5de7"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12-1024x576.png\" alt=\"9 Tricks with the Python REPL\" class=\"wp-image-4735\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12-1024x576.png 1024w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12-300x169.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12-768x432.png 768w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12-18x10.png 18w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>Of course, the <em>Pi<\/em> in <em>Raspberry Pi <\/em>comes from Python, one of the most popular programming languages in the world and especially popular among tinkerers and makers. In this post, I want to give you 9 tricks and tips with the Python REPL &#8211; but don&#8217;t worry if you&#8217;re not super familiar with <a href=\"https:\/\/picockpit.com\/raspberry-pi\/category\/python\/\">Python<\/a> or the REPL. <\/p>\n\n\n\n<p>This post is aimed and both beginners and intermediate Python programmers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is the REPL?<\/h2>\n\n\n\n<p>The REPL, or Read-Evaluate-Print Loop, is a way to directly interact with the Python interpreter. It&#8217;s called a REPL, because it reads, evaluates, and prints the input and then loops back to the beginning, allowing you to enter another command.<\/p>\n\n\n\n<p>It provides a interface through a Python Shell to input code and immediately receive an output. This makes it possible to check code, debug in real-time, and produce interactive tests. Typically, you&#8217;ll know you&#8217;re dealing with a Python REPL once you see these three arrows:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&gt;&gt;&gt;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&gt;&gt;&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This is where you can place you input. <\/p>\n\n\n\n<p>It&#8217;s worth mentioning that <\/p>\n\n\n\n<p>The terms &#8220;Python Shell&#8221; and &#8220;Python Interpreter&#8221; are sometimes used interchangeably, but there is a subtle difference between them. The Python Interpreter refers to the actual program or software that executes Python code. The Python Shell, however, is the interface that allows you to interact with the interpreter in real-time.<\/p>\n\n\n\n<p>Aside from the standard Python and Python3 Shells, many people also use IPython and bpython, which are command line programs that offer unique features, such as syntax highlighting.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"672\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-12-55-00-1024x672.png\" alt=\"Python REPL\" class=\"wp-image-4183\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-12-55-00-1024x672.png 1024w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-12-55-00-300x197.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-12-55-00-768x504.png 768w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-12-55-00-18x12.png 18w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-12-55-00.png 1473w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>You can see that IPython and bpython are prettier by default (below we&#8217;ll see how to make the standard REPL prettier as well). <\/p>\n\n\n\n<p>It&#8217;s also worth noting that IPython&#8217;s REPL numbers input lines &#8220;In [1]&#8221;, &#8220;In [2]&#8221;, etc. <\/p>\n\n\n\n<p>In contrast to IPython, bpython maintains the &gt;&gt;&gt; layout.<\/p>\n\n\n\n<p>The REPL can also provide features like command history, tab completion, and the ability to access previously defined variables and functions, making it a convenient tool for interactive Python programming and exploration.<\/p>\n\n\n\n<p>This makes the REPL an invaluable tool for anyone who is looking to mess around with their Raspberry Pi.<\/p>\n\n\n\n<p>Now that you&#8217;re up to speed on what the REPL is, let&#8217;s explore some tricks for using it:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> Trick 1: Find Documentation<\/h2>\n\n\n\n<p>You can find the documentation for any Python object or module directly from the REPL by using the <code>help()<\/code> function. <\/p>\n\n\n\n<p>For example, typing <code>help(str)<\/code> will display the documentation for the string object. You can also append a specific method or function name to get detailed information, such as<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\" help(str.upper)\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">help<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">str<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">upper<\/span><span style=\"color: #D8DEE9FF\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>If you type this in, you&#8217;ll see the following:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"533\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-21-15.png\" alt=\"Python REPL find documentation\" class=\"wp-image-4184\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-21-15.png 786w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-21-15-300x203.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-21-15-768x521.png 768w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-21-15-18x12.png 18w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Trick 2: Utilize Tab Completion<\/h2>\n\n\n\n<p>Depending on which program you&#8217;re using, the Python REPL supports tab completion, which can save you time and prevent typos. Pressing the Tab key after typing a partial name or object will display available options. <\/p>\n\n\n\n<p>For example, if you type <code>int.<\/code> and then press Tab, you&#8217;ll see a list of methods to run with integers.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"89\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-21-15.png\" alt=\"Python REPL tab completion\" class=\"wp-image-4185\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-21-15.png 721w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-21-15-300x37.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-21-15-18x2.png 18w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"> Trick 3: Create Multi-Line Statements<\/h2>\n\n\n\n<p>Furthermore, the REPL will allow you to write multi-line statements using line continuation. <\/p>\n\n\n\n<p>If you want to break a statement into multiple lines for readability, you can use the backslash character (<code>\\<\/code>) at the end of each line to continue it onto the next line (see example 1 below). <\/p>\n\n\n\n<p>You can also put the statement in parentheses or brackets to continue it onto the next line (see example 2 below). <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"# example 1: using backslash for a multi-line statement\n\nname = 'Fatima'\nage = 46\ncountry = 'Germany'\n\nmessage = 'Hi, ' + \\\n          name + \\\n          '! You are ' + \\\n          str(age) + \\\n          ' years old and from ' + \\\n          country + '.'\n\nprint(message)\n\n# the message will be 'Hi, Fatima! You are 46 years old and from Germany.'\n\n# example 2: using parentheses for a multi-line statement\n\ntotal = (1 + 2 + 3 +\n         4 + 5 + 6 +\n         7 + 8 + 9)\n\nprint(&quot;The total is:&quot;, total)\n\n# the message will be 'The total is: 45'\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\"># <\/span><span style=\"color: #D8DEE9\">example<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\">: <\/span><span style=\"color: #D8DEE9\">using<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">backslash<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">for<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">a<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">multi<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9\">line<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">statement<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">name<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Fatima<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">age<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">46<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">country<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Germany<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">message<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Hi, <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> \\<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          <\/span><span style=\"color: #D8DEE9\">name<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> \\<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">! You are <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> \\<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          <\/span><span style=\"color: #88C0D0\">str<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">age<\/span><span style=\"color: #D8DEE9FF\">) <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> \\<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\"> years old and from <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> \\<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">          <\/span><span style=\"color: #D8DEE9\">country<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">.<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">message<\/span><span style=\"color: #D8DEE9FF\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\"># <\/span><span style=\"color: #D8DEE9\">the<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">message<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">will<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">be<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Hi, Fatima! You are 46 years old and from Germany.<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\"># <\/span><span style=\"color: #D8DEE9\">example<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\">: <\/span><span style=\"color: #D8DEE9\">using<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">parentheses<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">for<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">a<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">multi<\/span><span style=\"color: #81A1C1\">-<\/span><span style=\"color: #D8DEE9\">line<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">statement<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">total<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">3<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">         <\/span><span style=\"color: #B48EAD\">4<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">5<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">6<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">         <\/span><span style=\"color: #B48EAD\">7<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">8<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">+<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">9<\/span><span style=\"color: #D8DEE9FF\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #88C0D0\">print<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">The total is:<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">total<\/span><span style=\"color: #D8DEE9FF\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\"># <\/span><span style=\"color: #D8DEE9\">the<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">message<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">will<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">be<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">The total is: 45<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"> Trick 4: Access Previously-Typed Code<\/h2>\n\n\n\n<p>You can access previously typed code in the REPL using the up and down arrow keys, just like you would in the terminal. <\/p>\n\n\n\n<p>Pressing the up arrow key will cycle through your command history, allowing you to quickly recall and modify previous commands. Check it out for yourself!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> Trick 5: Make Use of the Underscore Variable<\/h2>\n\n\n\n<p>The underscore variable (<code>_)<\/code> holds the result of the last expression evaluated in the REPL. <\/p>\n\n\n\n<p>It can come in handy when you need to reuse the result in subsequent operations without having to reevaluate the entire expression. So if you need to do some quick calculations or if you want to retrieve data super fast &#8211; you can just type in the underscore as a standard variable of the previous result.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"533\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-18-30.png\" alt=\"Python REPL underscore variable\" class=\"wp-image-4186\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-18-30.png 786w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-18-30-300x203.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-18-30-768x521.png 768w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-14-18-30-18x12.png 18w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"> Trick 6: Execute System Commands &amp; Magic Commands (IPython)<\/h2>\n\n\n\n<p>In IPython (short for &#8220;Interactive Python&#8221;), you can execute system commands directly by prefixing a line of code with an exclamation mark (<code>!<\/code>). <\/p>\n\n\n\n<p>Together with IPython&#8217;s <a href=\"https:\/\/ipython.readthedocs.io\/en\/stable\/interactive\/magics.html\">magic commands<\/a>, like %cd to change directory, you&#8217;re able to use the Python REPL for seamless integration!<\/p>\n\n\n\n<p>For example, <code>!ls<\/code> on Unix-based systems or <code>!dir<\/code> on Windows will list the contents of the current directory.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"663\" height=\"275\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-56-36.png\" alt=\"Python REPL magic commands\" class=\"wp-image-4187\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-56-36.png 663w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-56-36-300x124.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-10-15-56-36-18x7.png 18w\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"> Trick 7: Experiment with Imports<\/h2>\n\n\n\n<p>In the Python REPL, you can experiment with imports without the need to create separate Python files. This feature allows you to import modules, try out their functions, and explore their contents interactively, making it convenient for quick experimentation and exploration of different modules and their capabilities.<\/p>\n\n\n\n<p>Here&#8217;s how you can use the Python REPL to experiment with imports:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&gt;&gt;&gt; import math\n&gt;&gt;&gt; math.sqrt(16)\n4.0\n\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&gt;&gt;&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">import<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">math<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">&gt;&gt;&gt; <\/span><span style=\"color: #8FBCBB\">math<\/span><span style=\"color: #D8DEE9FF\">.<\/span><span style=\"color: #8FBCBB\">sqrt<\/span><span style=\"color: #D8DEE9FF\">(16)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">4.0<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this example, we use the <code>sqrt()<\/code> function from the <code>math<\/code> module to calculate the square root of 16.<\/p>\n\n\n\n<p>By using the Python REPL to experiment with imports, you can quickly test and explore the functionality of various modules without the need to create separate Python files. <\/p>\n\n\n\n<p>This interactive and iterative process allows you to gain a better understanding of how different modules work, try out different functions, and examine their results in real-time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> Trick 8: Customize the REPL Prompt<\/h2>\n\n\n\n<p>Don&#8217;t like the &gt;&gt;&gt; as your primary prompt and &#8230; as your secondary prompt?<\/p>\n\n\n\n<p>You&#8217;re in luck, because you can customize the prompt displayed by the Python REPL. <\/p>\n\n\n\n<p>By modifying the <code>sys.ps1<\/code> and <code>sys.ps2<\/code> variables, you can change the primary and secondary prompts, respectively.<\/p>\n\n\n\n<p>Just run:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"import sys\n\nsys.ps1 = 'primary'\nsys.ps2 = 'secondary'\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">import<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">sys<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #8FBCBB\">sys<\/span><span style=\"color: #D8DEE9FF\">.<\/span><span style=\"color: #8FBCBB\">ps1<\/span><span style=\"color: #D8DEE9FF\"> = <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">primary<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #8FBCBB\">sys<\/span><span style=\"color: #D8DEE9FF\">.<\/span><span style=\"color: #8FBCBB\">ps2<\/span><span style=\"color: #D8DEE9FF\"> = <\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">secondary<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now, the primary prompt will be &#8220;primary&#8221; and the secondary prompt will read &#8220;secondary&#8221;. Feel free to change it up to whatever you like! Try it out with symbols or emojis, for instance!<\/p>\n\n\n\n<p>Doing it this way will only affect the current REPL session. If you want to make things a little more permanent, then you&#8217;re going to need to find the &#8220;.pyrc&#8221; file and edit the prompts there.<\/p>\n\n\n\n<p>Remember my boring, ugly prompters in my REPLs above? Let&#8217;s change the color.<\/p>\n\n\n\n<p>If you&#8217;re using Linux, then you can plug in the following into your terminal:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"tee ~\/.pyrc &lt;&lt;E0F\nimport sys\nsys.ps1='\\x01\\x1b[1;34;40m\\x02&gt;&gt;&gt;\\x01\\x1b[0m\\x02'\nsys.ps2='\\x01\\x1b[1;35;40m\\x02...\\x01\\x1b[0m\\x02'\nE0F\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9\">tee<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">~\/<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">pyrc<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">&lt;&lt;<\/span><span style=\"color: #D8DEE9\">E0F<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">import<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">sys<\/span><\/span>\n<span class=\"line\"><span style=\"color: #8FBCBB\">sys<\/span><span style=\"color: #D8DEE9FF\">.<\/span><span style=\"color: #8FBCBB\">ps1<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #EBCB8B\">\\x01\\x1b<\/span><span style=\"color: #A3BE8C\">[1;34;40m<\/span><span style=\"color: #EBCB8B\">\\x02<\/span><span style=\"color: #A3BE8C\">&gt;&gt;&gt;<\/span><span style=\"color: #EBCB8B\">\\x01\\x1b<\/span><span style=\"color: #A3BE8C\">[0m<\/span><span style=\"color: #EBCB8B\">\\x02<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #8FBCBB\">sys<\/span><span style=\"color: #D8DEE9FF\">.<\/span><span style=\"color: #8FBCBB\">ps2<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #EBCB8B\">\\x01\\x1b<\/span><span style=\"color: #A3BE8C\">[1;35;40m<\/span><span style=\"color: #EBCB8B\">\\x02<\/span><span style=\"color: #A3BE8C\">...<\/span><span style=\"color: #EBCB8B\">\\x01\\x1b<\/span><span style=\"color: #A3BE8C\">[0m<\/span><span style=\"color: #EBCB8B\">\\x02<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #8FBCBB\">E0F<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This will change the color of the primary prompt to a blue on grey and the secondary prompt to a purple on grey, if you&#8217;re looking for that. Feel free to experiment with all the <a href=\"https:\/\/azrael.digipen.edu\/~mmead\/www\/mg\/ansicolors\/index.html\">ANSI color sequences<\/a> to find a prompter color you&#8217;re happy with.<\/p>\n\n\n\n<p>Once you&#8217;ve done that, make sure to export this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"export PYTHONSTARTUP=~\/.pyrc\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">export<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">PYTHONSTARTUP<\/span><span style=\"color: #81A1C1\">=~\/<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">pyrc<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Now you&#8217;re prompts should look like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"533\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-00-49.png\" alt=\"Python REPL customize prompt\" class=\"wp-image-4188\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-00-49.png 786w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-00-49-300x203.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-00-49-768x521.png 768w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-00-49-18x12.png 18w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/figure>\n<\/div>\n\n\n<p>Again, this is only temporary. If you want to permanently change things, you&#8217;re going to have to change the configuration file. But it gives you a taste of the fun to be had!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> Trick 9: Explore Modules &amp; Objects <\/h2>\n\n\n\n<p>If you&#8217;re looking to complement finding documentation and utilizing tab completion, then this is the trick that completes the package!<\/p>\n\n\n\n<p>You can explore the contents of a module (or an object) by using the <code>dir()<\/code> function. <\/p>\n\n\n\n<p>By passing a module or object as an argument, it returns a list of names within that module or object, allowing you to explore its available attributes, methods, and functions.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"import math\nprint (dir(math))\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">import<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">math<\/span><\/span>\n<span class=\"line\"><span style=\"color: #8FBCBB\">print<\/span><span style=\"color: #D8DEE9FF\"> (<\/span><span style=\"color: #8FBCBB\">dir<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #8FBCBB\">math<\/span><span style=\"color: #D8DEE9FF\">))<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This will display a list of the available attributes, methods, and functions within the math module.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"533\" src=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-58-25.png\" alt=\"Python REPL explore modules &amp; objects\" class=\"wp-image-4189\" srcset=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-58-25.png 786w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-58-25-300x203.png 300w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-58-25-768x521.png 768w, https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-11-13-58-25-18x12.png 18w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/figure>\n<\/div>\n\n\n<p>It&#8217;s tricks like this can be instrumental in making your workflow seamless.<\/p>\n\n\n\n<p>Once you&#8217;ve got these 9 tricks down, you&#8217;ll be able to use the REPL more effectively. <\/p>\n\n\n\n<p>This will make debugging and testing your code go much smoother.<\/p>\n\n\n\n<p>Let us know what REPL tricks you&#8217;ve got in the comments below!<\/p>\n<div class=\"shariff shariff-align-center shariff-widget-align-left shariff-buttonstretch\"><ul class=\"shariff-buttons theme-white orientation-horizontal buttonsize-medium\"><li class=\"shariff-button twitter shariff-nocustomcolor\" style=\"background-color:#595959\"><a href=\"https:\/\/twitter.com\/share?url=https%3A%2F%2Fpicockpit.com%2Fraspberry-pi%2Fzh%2F9%25e7%25a7%258dpython%25e6%259b%25bf%25e6%258d%25a2%25e6%258a%2580%25e5%25b7%25a7%2F&text=9%20Tricks%20with%20the%20Python%20REPL\" title=\"Share on X\" aria-label=\"Share on X\" role=\"button\" rel=\"noopener nofollow\" class=\"shariff-link\" style=\"; background-color:#000; color:#000\" target=\"_blank\"><span class=\"shariff-icon\" style=\"fill:#000\"><svg width=\"32px\" height=\"20px\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\"><path fill=\"#000\" d=\"M14.258 10.152L23.176 0h-2.113l-7.747 8.813L7.133 0H0l9.352 13.328L0 23.973h2.113l8.176-9.309 6.531 9.309h7.133zm-2.895 3.293l-.949-1.328L2.875 1.56h3.246l6.086 8.523.945 1.328 7.91 11.078h-3.246zm0 0\"\/><\/svg><\/span><span class=\"shariff-text\" style=\"color:#000\">\u5206\u4eab<\/span>&nbsp;<\/a><\/li><li class=\"shariff-button facebook shariff-nocustomcolor\" style=\"background-color:#4273c8\"><a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fpicockpit.com%2Fraspberry-pi%2Fzh%2F9%25e7%25a7%258dpython%25e6%259b%25bf%25e6%258d%25a2%25e6%258a%2580%25e5%25b7%25a7%2F\" title=\"\u5728Facebook\u4e0a\u5206\u4eab\" aria-label=\"\u5728Facebook\u4e0a\u5206\u4eab\" role=\"button\" rel=\"nofollow\" class=\"shariff-link\" style=\"; background-color:#3b5998; color:#3b5998\" target=\"_blank\"><span class=\"shariff-icon\" style=\"fill:#3b5998\"><svg width=\"32px\" height=\"20px\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 18 32\"><path fill=\"#3b5998\" d=\"M17.1 0.2v4.7h-2.8q-1.5 0-2.1 0.6t-0.5 1.9v3.4h5.2l-0.7 5.3h-4.5v13.6h-5.5v-13.6h-4.5v-5.3h4.5v-3.9q0-3.3 1.9-5.2t5-1.8q2.6 0 4.1 0.2z\"\/><\/svg><\/span><span class=\"shariff-text\" style=\"color:#3b5998\">\u5206\u4eab<\/span>&nbsp;<\/a><\/li><li class=\"shariff-button telegram shariff-nocustomcolor\" style=\"background-color:#4084A6\"><a href=\"https:\/\/telegram.me\/share\/url?url=https%3A%2F%2Fpicockpit.com%2Fraspberry-pi%2Fzh%2F9%25e7%25a7%258dpython%25e6%259b%25bf%25e6%258d%25a2%25e6%258a%2580%25e5%25b7%25a7%2F&text=9%20Tricks%20with%20the%20Python%20REPL\" title=\"\u5728Telegram\u4e0a\u5206\u4eab\" aria-label=\"\u5728Telegram\u4e0a\u5206\u4eab\" role=\"button\" rel=\"noopener nofollow\" class=\"shariff-link\" style=\"; background-color:#0088cc; color:#0088cc\" target=\"_blank\"><span class=\"shariff-icon\" style=\"fill:#0088cc\"><svg width=\"32px\" height=\"20px\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 32 32\"><path fill=\"#0088cc\" d=\"M30.8 6.5l-4.5 21.4c-.3 1.5-1.2 1.9-2.5 1.2L16.9 24l-3.3 3.2c-.4.4-.7.7-1.4.7l.5-7L25.5 9.2c.6-.5-.1-.8-.9-.3l-15.8 10L2 16.7c-1.5-.5-1.5-1.5.3-2.2L28.9 4.3c1.3-.5 2.3.3 1.9 2.2z\"\/><\/svg><\/span><span class=\"shariff-text\" style=\"color:#0088cc\">\u5206\u4eab<\/span>&nbsp;<\/a><\/li><li class=\"shariff-button reddit shariff-nocustomcolor\" style=\"background-color:#ff5700\"><a href=\"https:\/\/www.reddit.com\/submit?url=https%3A%2F%2Fpicockpit.com%2Fraspberry-pi%2Fzh%2F9%25e7%25a7%258dpython%25e6%259b%25bf%25e6%258d%25a2%25e6%258a%2580%25e5%25b7%25a7%2F\" title=\"\u5206\u4eab\u81f3Reddit\" aria-label=\"\u5206\u4eab\u81f3Reddit\" role=\"button\" rel=\"noopener nofollow\" class=\"shariff-link\" style=\"; background-color:#ff4500; color:#ff4500\" target=\"_blank\"><span class=\"shariff-icon\" style=\"fill:#ff4500\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path fill=\"#ff4500\" d=\"M440.3 203.5c-15 0-28.2 6.2-37.9 15.9-35.7-24.7-83.8-40.6-137.1-42.3L293 52.3l88.2 19.8c0 21.6 17.6 39.2 39.2 39.2 22 0 39.7-18.1 39.7-39.7s-17.6-39.7-39.7-39.7c-15.4 0-28.7 9.3-35.3 22l-97.4-21.6c-4.9-1.3-9.7 2.2-11 7.1L246.3 177c-52.9 2.2-100.5 18.1-136.3 42.8-9.7-10.1-23.4-16.3-38.4-16.3-55.6 0-73.8 74.6-22.9 100.1-1.8 7.9-2.6 16.3-2.6 24.7 0 83.8 94.4 151.7 210.3 151.7 116.4 0 210.8-67.9 210.8-151.7 0-8.4-.9-17.2-3.1-25.1 49.9-25.6 31.5-99.7-23.8-99.7zM129.4 308.9c0-22 17.6-39.7 39.7-39.7 21.6 0 39.2 17.6 39.2 39.7 0 21.6-17.6 39.2-39.2 39.2-22 .1-39.7-17.6-39.7-39.2zm214.3 93.5c-36.4 36.4-139.1 36.4-175.5 0-4-3.5-4-9.7 0-13.7 3.5-3.5 9.7-3.5 13.2 0 27.8 28.5 120 29 149 0 3.5-3.5 9.7-3.5 13.2 0 4.1 4 4.1 10.2.1 13.7zm-.8-54.2c-21.6 0-39.2-17.6-39.2-39.2 0-22 17.6-39.7 39.2-39.7 22 0 39.7 17.6 39.7 39.7-.1 21.5-17.7 39.2-39.7 39.2z\"\/><\/svg><\/span><span class=\"shariff-text\" style=\"color:#ff4500\">\u5206\u4eab<\/span>&nbsp;<\/a><\/li><\/ul><\/div>","protected":false},"excerpt":{"rendered":"<p>\u5f53\u7136\uff0c\u6811\u8393\u6d3e\u4e2d\u7684 Pi \u6765\u81ea Python\uff0c\u5b83\u662f\u4e16\u754c\u4e0a\u6700\u6d41\u884c\u7684\u7f16\u7a0b\u8bed\u8a00\u4e4b\u4e00\uff0c\u5728\u5de5\u5320\u548c\u521b\u5ba2\u4e2d\u5c24\u5176\u53d7\u6b22\u8fce\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u4e3a\u60a8\u4ecb\u7ecd\u4f7f\u7528 Python REPL \u7684 9 \u4e2a\u6280\u5de7\u548c\u7a8d\u95e8--\u4e0d\u8fc7\uff0c\u5982\u679c\u60a8\u5bf9 Python \u4e0d\u662f\u5f88\u719f\u6089\uff0c\u4e5f\u4e0d\u7528\u62c5\u5fc3\u3002<\/p>","protected":false},"author":2,"featured_media":4735,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1193,3],"tags":[1319,477,1322,1317,1318,606,1324,14,476,1320,1321,1097,649,187,456,1316,993,1010,1323],"class_list":["post-4092","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-raspberry-pi-how-to","tag-bpython","tag-circuitpython","tag-documentation","tag-interpreter","tag-ipython","tag-linux","tag-magic-commands","tag-micropython","tag-python","tag-python-2","tag-python-3","tag-python-3-7","tag-python-practice","tag-raspberry-pi","tag-raspberry-pi-projects","tag-read-eval-print-loop","tag-repl","tag-shell","tag-system-commands"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>9 Tricks with the Python REPL | PiCockpit<\/title>\n<meta name=\"description\" content=\"In this post, we look at different tricks and tips for using the Python REPL, especially for beginners and intermediate programmers!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/picockpit.com\/raspberry-pi\/zh\/9\u79cdpython\u66ff\u6362\u6280\u5de7\/\" \/>\n<meta property=\"og:locale\" content=\"zh_HK\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"9 Tricks with the Python REPL | PiCockpit\" \/>\n<meta property=\"og:description\" content=\"In this post, we look at different tricks and tips for using the Python REPL, especially for beginners and intermediate programmers!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/picockpit.com\/raspberry-pi\/zh\/9\u79cdpython\u66ff\u6362\u6280\u5de7\/\" \/>\n<meta property=\"og:site_name\" content=\"PiCockpit\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pi3gshop\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-11T12:27:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-11T10:47:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"raspi berry\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pi3g\" \/>\n<meta name=\"twitter:site\" content=\"@pi3g\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"raspi berry\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9810\u8a08\u95b1\u8b80\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\u9418\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/\"},\"author\":{\"name\":\"raspi berry\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#\\\/schema\\\/person\\\/7af3a7a8c999bc722029ef9ca9d78eee\"},\"headline\":\"9 Tricks with the Python REPL\",\"datePublished\":\"2023-07-11T12:27:49+00:00\",\"dateModified\":\"2023-08-11T10:47:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/\"},\"wordCount\":1294,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Untitled12.png\",\"keywords\":[\"bpython\",\"circuitpython\",\"documentation\",\"Interpreter\",\"IPython\",\"linux\",\"magic commands\",\"microPython\",\"python\",\"python 2\",\"python 3\",\"python 3.7\",\"Python practice\",\"Raspberry Pi\",\"Raspberry Pi projects\",\"Read-Eval-Print Loop\",\"repl\",\"shell\",\"system commands\"],\"articleSection\":[\"Python\",\"Tutorials\"],\"inLanguage\":\"zh-HK\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/\",\"url\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/\",\"name\":\"9 Tricks with the Python REPL | PiCockpit\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Untitled12.png\",\"datePublished\":\"2023-07-11T12:27:49+00:00\",\"dateModified\":\"2023-08-11T10:47:40+00:00\",\"description\":\"In this post, we look at different tricks and tips for using the Python REPL, especially for beginners and intermediate programmers!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#breadcrumb\"},\"inLanguage\":\"zh-HK\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-HK\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#primaryimage\",\"url\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Untitled12.png\",\"contentUrl\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Untitled12.png\",\"width\":1200,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/9-tricks-with-the-python-repl\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/category\\\/raspberry-pi-how-to\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"9 Tricks with the Python REPL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#website\",\"url\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/\",\"name\":\"PiCockpit\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-HK\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#organization\",\"name\":\"PiCockpit.com\",\"url\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-HK\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Screenshot-from-2023-07-24-15-01-24.png\",\"contentUrl\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/Screenshot-from-2023-07-24-15-01-24.png\",\"width\":1165,\"height\":283,\"caption\":\"PiCockpit.com\"},\"image\":{\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/pi3gshop\",\"https:\\\/\\\/x.com\\\/pi3g\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/#\\\/schema\\\/person\\\/7af3a7a8c999bc722029ef9ca9d78eee\",\"name\":\"raspi berry\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-HK\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c10c423ceeff34163dd54a5472d6da17d71c0e360e0cf8cdb8847006372f216b?s=96&d=blank&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c10c423ceeff34163dd54a5472d6da17d71c0e360e0cf8cdb8847006372f216b?s=96&d=blank&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c10c423ceeff34163dd54a5472d6da17d71c0e360e0cf8cdb8847006372f216b?s=96&d=blank&r=g\",\"caption\":\"raspi berry\"},\"description\":\"I'm here to help you with all your Raspberry Pi related questions &amp; love to share about new project ideas for the Raspberry Pi, and give quick tips. Of course I'll also help you with PiCockpit and how to make your Raspberry Pi even easier to use with this raspberry pi monitoring solution :-)\",\"sameAs\":[\"https:\\\/\\\/picockpit.com\"],\"url\":\"https:\\\/\\\/picockpit.com\\\/raspberry-pi\\\/zh\\\/author\\\/raspi-berry\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528 Python REPL \u7684 9 \u4e2a\u6280\u5de7 | PiCockpit","description":"\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4f7f\u7528 Python REPL \u7684\u5404\u79cd\u6280\u5de7\u548c\u7a8d\u95e8\uff0c\u5c24\u5176\u662f\u9488\u5bf9\u521d\u5b66\u8005\u548c\u4e2d\u7ea7\u7a0b\u5e8f\u5458\uff01","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/picockpit.com\/raspberry-pi\/zh\/9\u79cdpython\u66ff\u6362\u6280\u5de7\/","og_locale":"zh_HK","og_type":"article","og_title":"9 Tricks with the Python REPL | PiCockpit","og_description":"In this post, we look at different tricks and tips for using the Python REPL, especially for beginners and intermediate programmers!","og_url":"https:\/\/picockpit.com\/raspberry-pi\/zh\/9\u79cdpython\u66ff\u6362\u6280\u5de7\/","og_site_name":"PiCockpit","article_publisher":"https:\/\/www.facebook.com\/pi3gshop","article_published_time":"2023-07-11T12:27:49+00:00","article_modified_time":"2023-08-11T10:47:40+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12.png","type":"image\/png"}],"author":"raspi berry","twitter_card":"summary_large_image","twitter_creator":"@pi3g","twitter_site":"@pi3g","twitter_misc":{"\u4f5c\u8005":"raspi berry","\u9810\u8a08\u95b1\u8b80\u6642\u9593":"8 \u5206\u9418"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#article","isPartOf":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/"},"author":{"name":"raspi berry","@id":"https:\/\/picockpit.com\/raspberry-pi\/#\/schema\/person\/7af3a7a8c999bc722029ef9ca9d78eee"},"headline":"9 Tricks with the Python REPL","datePublished":"2023-07-11T12:27:49+00:00","dateModified":"2023-08-11T10:47:40+00:00","mainEntityOfPage":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/"},"wordCount":1294,"commentCount":0,"publisher":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/#organization"},"image":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#primaryimage"},"thumbnailUrl":"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12.png","keywords":["bpython","circuitpython","documentation","Interpreter","IPython","linux","magic commands","microPython","python","python 2","python 3","python 3.7","Python practice","Raspberry Pi","Raspberry Pi projects","Read-Eval-Print Loop","repl","shell","system commands"],"articleSection":["Python","Tutorials"],"inLanguage":"zh-HK","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/","url":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/","name":"\u4f7f\u7528 Python REPL \u7684 9 \u4e2a\u6280\u5de7 | PiCockpit","isPartOf":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/#website"},"primaryImageOfPage":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#primaryimage"},"image":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#primaryimage"},"thumbnailUrl":"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12.png","datePublished":"2023-07-11T12:27:49+00:00","dateModified":"2023-08-11T10:47:40+00:00","description":"\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4f7f\u7528 Python REPL \u7684\u5404\u79cd\u6280\u5de7\u548c\u7a8d\u95e8\uff0c\u5c24\u5176\u662f\u9488\u5bf9\u521d\u5b66\u8005\u548c\u4e2d\u7ea7\u7a0b\u5e8f\u5458\uff01","breadcrumb":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#breadcrumb"},"inLanguage":"zh-HK","potentialAction":[{"@type":"ReadAction","target":["https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/"]}]},{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#primaryimage","url":"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12.png","contentUrl":"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Untitled12.png","width":1200,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/picockpit.com\/raspberry-pi\/9-tricks-with-the-python-repl\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/picockpit.com\/raspberry-pi\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/picockpit.com\/raspberry-pi\/category\/raspberry-pi-how-to\/"},{"@type":"ListItem","position":3,"name":"9 Tricks with the Python REPL"}]},{"@type":"WebSite","@id":"https:\/\/picockpit.com\/raspberry-pi\/#website","url":"https:\/\/picockpit.com\/raspberry-pi\/","name":"\u7801\u5934","description":"","publisher":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/picockpit.com\/raspberry-pi\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-HK"},{"@type":"Organization","@id":"https:\/\/picockpit.com\/raspberry-pi\/#organization","name":"PiCockpit.com","url":"https:\/\/picockpit.com\/raspberry-pi\/","logo":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/picockpit.com\/raspberry-pi\/#\/schema\/logo\/image\/","url":"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-24-15-01-24.png","contentUrl":"https:\/\/picockpit.com\/raspberry-pi\/wp-content\/uploads\/2023\/07\/Screenshot-from-2023-07-24-15-01-24.png","width":1165,"height":283,"caption":"PiCockpit.com"},"image":{"@id":"https:\/\/picockpit.com\/raspberry-pi\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pi3gshop","https:\/\/x.com\/pi3g"]},{"@type":"Person","@id":"https:\/\/picockpit.com\/raspberry-pi\/#\/schema\/person\/7af3a7a8c999bc722029ef9ca9d78eee","name":"raspi berry","image":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/secure.gravatar.com\/avatar\/c10c423ceeff34163dd54a5472d6da17d71c0e360e0cf8cdb8847006372f216b?s=96&d=blank&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c10c423ceeff34163dd54a5472d6da17d71c0e360e0cf8cdb8847006372f216b?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c10c423ceeff34163dd54a5472d6da17d71c0e360e0cf8cdb8847006372f216b?s=96&d=blank&r=g","caption":"raspi berry"},"description":"\u6211\u5728\u8fd9\u91cc\u5e2e\u52a9\u4f60\u89e3\u51b3\u6240\u6709\u4e0e\u6811\u8393\u6d3e\u6709\u5173\u7684\u95ee\u9898\uff0c\u5e76\u559c\u6b22\u5206\u4eab\u6709\u5173\u6811\u8393\u6d3e\u7684\u65b0\u9879\u76ee\u60f3\u6cd5\uff0c\u5e76\u7ed9\u51fa\u5feb\u901f\u63d0\u793a\u3002\u5f53\u7136\uff0c\u6211\u4e5f\u4f1a\u5e2e\u52a9\u4f60\u4e86\u89e3PiCockpit\uff0c\u4ee5\u53ca\u5982\u4f55\u5229\u7528\u8fd9\u4e2a\u6811\u8393\u6d3e\u76d1\u63a7\u89e3\u51b3\u65b9\u6848\u4f7f\u4f60\u7684\u6811\u8393\u6d3e\u66f4\u5bb9\u6613\u4f7f\u7528 :-)","sameAs":["https:\/\/picockpit.com"],"url":"https:\/\/picockpit.com\/raspberry-pi\/zh\/author\/raspi-berry\/"}]}},"_links":{"self":[{"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/posts\/4092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/comments?post=4092"}],"version-history":[{"count":29,"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/posts\/4092\/revisions"}],"predecessor-version":[{"id":4737,"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/posts\/4092\/revisions\/4737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/media\/4735"}],"wp:attachment":[{"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/media?parent=4092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/categories?post=4092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/picockpit.com\/raspberry-pi\/zh\/wp-json\/wp\/v2\/tags?post=4092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}