<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Python on ChengAo Shen</title>
    <link>https://chengaoshen.com/en/tags/python/</link>
    <description>Recent content in Python on ChengAo Shen</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sat, 21 Jan 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://chengaoshen.com/en/tags/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>🖊️Effective Python Tips</title>
      <link>https://chengaoshen.com/en/posts/effective-python-tips/</link>
      <pubDate>Sat, 21 Jan 2023 00:00:00 +0000</pubDate>
      <guid>https://chengaoshen.com/en/posts/effective-python-tips/</guid>
      <description>&lt;h2 id=&#34;1-pythonic-thinking&#34;&gt;&#xA;  1. Pythonic Thinking&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#1-pythonic-thinking&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;Link to heading&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;Link to heading&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h2&gt;&#xA;&lt;h3 id=&#34;11-follow-pep8-style&#34;&gt;&#xA;  1.1 Follow PEP8 Style&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#11-follow-pep8-style&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;Link to heading&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;Link to heading&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Regarding Naming&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Functions, variables, and attributes use lowercase letters, with words separated by underscores.&lt;/li&gt;&#xA;&lt;li&gt;Protected instance attributes start with a single underscore.&lt;/li&gt;&#xA;&lt;li&gt;Private instance attributes should start with two underscores.&lt;/li&gt;&#xA;&lt;li&gt;Class (and exception) names should have the first letter capitalized.&lt;/li&gt;&#xA;&lt;li&gt;Module-level constants are all uppercase letters, with words separated by underscores.&lt;/li&gt;&#xA;&lt;li&gt;Instance methods in classes should name the first parameter &lt;code&gt;self&lt;/code&gt; to represent the object itself.&lt;/li&gt;&#xA;&lt;li&gt;The first parameter of class methods should be named &lt;code&gt;cls&lt;/code&gt; to represent the class itself.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Regarding Expressions&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Use inline negation (write the negation directly before the content to be negated). For example: &lt;code&gt;if a is not b&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;To check if something is empty, you can directly test it (empty is False). For example: &lt;code&gt;if not somelist&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;If an expression does not fit on one line, it should be enclosed in parentheses and broken into multiple lines.&lt;/li&gt;&#xA;&lt;li&gt;Use parentheses to continue multi-line expressions instead of the backslash &lt;code&gt;\&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Regarding Imports&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;code&gt;import&lt;/code&gt; statements should be placed at the top.&lt;/li&gt;&#xA;&lt;li&gt;Use absolute names for imports.&lt;/li&gt;&#xA;&lt;li&gt;When importing, first divide into three parts: standard library, third-party modules, and your own modules.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;12-use-f-strings-for-string-interpolation&#34;&gt;&#xA;  1.2 Use f-strings for String Interpolation&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#12-use-f-strings-for-string-interpolation&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;Link to heading&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;Link to heading&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h3&gt;&#xA;&lt;p&gt;  When formatting strings, you can use Python&amp;rsquo;s special &lt;strong&gt;f-string&lt;/strong&gt; method.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
