<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/category/python/</link>
	<description></description>
	<lastBuildDate>Tue, 30 Jun 2020 01:04:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>Python Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/category/python/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Iterables in Python</title>
		<link>https://zxi.mytechroad.com/blog/python/iterables-in-python/</link>
					<comments>https://zxi.mytechroad.com/blog/python/iterables-in-python/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Tue, 30 Jun 2020 01:04:13 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[expcetion]]></category>
		<category><![CDATA[iterables]]></category>
		<category><![CDATA[iterator]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=7018</guid>

					<description><![CDATA[<p>Example Code: [crayon-663c5db106240156350840/]</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/python/iterables-in-python/">Iterables in Python</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="可迭代的 Iterables - Python Weekly EP4" width="500" height="281" src="https://www.youtube.com/embed/-PklUOOz4n8?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<h2><strong>Example Code:</strong></h2>



<div class="responsive-tabs">
<h2 class="tabtitle">Iterables in Python</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag"># Author: Huahua
class MyListIterator:
  def __init__(self, my_list, index=0):
    self.my_list = my_list
    self.index = index

  def __next__(self):
    if self.index &lt; len(self.my_list.data):
      val = self.my_list.data[self.index]
      self.index += 1
      return val
    else:
      raise StopIteration()

  def __iter__(self):
    return MyListIterator(self.my_list, self.index)
    # return self

class MyList:
  def __init__(self, data):
    self.data = list(data)

  def __getitem__(self, index):
    return self.data[index]

  def __len__(self):
    return len(self.data)

  def __iter__(self):
    return MyListIterator(self)

my_list = MyList([1,2,3,4,5])
it = iter(my_list)
next(it)
it2 = iter(it)
next(it)
print('--- it ---')
for x in it:
  print(x) # 3, 4, 5
print('--- it2 ---')
for x in it2:
  print(x) # 2, 3, 4, 5</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/python/iterables-in-python/">Iterables in Python</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/python/iterables-in-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>:= 海象运算符 Walrus Operator &#8211; Python Weekly EP2</title>
		<link>https://zxi.mytechroad.com/blog/python/walrus-operator-python-weekly-ep2/</link>
					<comments>https://zxi.mytechroad.com/blog/python/walrus-operator-python-weekly-ep2/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Fri, 29 May 2020 06:52:38 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python3.8]]></category>
		<category><![CDATA[walrus]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6830</guid>

					<description><![CDATA[<p>[crayon-663c5db10677a528705927/]</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/python/walrus-operator-python-weekly-ep2/">:= 海象运算符 Walrus Operator &#8211; Python Weekly EP2</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title=":= 海象运算符 Walrus Operator - Python Weekly EP2" width="500" height="375" src="https://www.youtube.com/embed/ojhTG9Ctt0I?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<div class="responsive-tabs">
<h2 class="tabtitle">Python3</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
import re
import io

# Example 1:
a = [0] * 100
if len(a) &gt; 10:
  print(f&quot;List is too long ({len(a)} elements, expected &lt;= 10)&quot;)

n = len(a)
if n &gt; 10:
  print(f&quot;List is too long ({n} elements, expected &lt;= 10)&quot;)

if (x := len(a)) &gt; 10:
  print(f&quot;List is too long ({x} elements, expected &lt;= 10)&quot;)

# Example 2, bad
ads = &quot;Now 20% off till 6/18&quot;

m1 = re.search(r'(\d+)% off', ads)
discount1 = float(m1.group(1)) / 100 if m1 else 0.0

discount2 = float(m2.group(1)) / 100 if (m2 := re.search(r'(\d+)% off', ads)) else 0.0

print(f'{discount1 = }, {discount2 = }')

# Example 3
f1 = io.StringIO(&quot;123456789&quot;)
x1 = f1.read(4)
while x1 != '':
  print(x1)
  x1 = f1.read(4)

f2 = io.StringIO(&quot;123456789&quot;)
while (x2 := f2.read(4)) != '':
  print(x2)

# Example 4
prog_langs = {'c++', 'python', 'java'}
langs = ['C++', 'Java', 'PYthon', 'English', '中文']

l1 = [lang.lower() for lang in langs if lang.lower() in prog_langs]
print(l1)

l2 = [l for lang in langs if (l := lang.lower()) in prog_langs]
print(l2)</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/python/walrus-operator-python-weekly-ep2/">:= 海象运算符 Walrus Operator &#8211; Python Weekly EP2</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/python/walrus-operator-python-weekly-ep2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>f-String in Python3</title>
		<link>https://zxi.mytechroad.com/blog/python/f-string-in-python3/</link>
					<comments>https://zxi.mytechroad.com/blog/python/f-string-in-python3/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Wed, 20 May 2020 04:35:48 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[f-string]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6801</guid>

					<description><![CDATA[<p>[crayon-663c5db1069df419712534/]</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/python/f-string-in-python3/">f-String in Python3</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="f-String - Python3 字符串格式化利器" width="500" height="375" src="https://www.youtube.com/embed/dwCeM1HNo5Y?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<div class="responsive-tabs">
<h2 class="tabtitle">Example code</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">name = 'Huahua'
score = 123.456789

print('name = ' + name + ', score = ' + str(score))
print('name = %s, score = %.3f' % (name, score))
print('name = {name}, score = {score:.3f}'.format(name=name, score=score))
print('name = {name}, score = {score:.3f}'.format(name='Huahua', score=123.456789))

print(f'name = {name}, score = {score:.3f}') # Python 3.6
print(f'{name = }, {score = :.3f}') # Python 3.8

def add(a, b):
  return a + b

k = 1
print(f'{k = }, {add(k, 2) = }') # k = 1, add(k, 2) = 3</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/python/f-string-in-python3/">f-String in Python3</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/python/f-string-in-python3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
