<?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-operator归档 - 帝讯博客</title>
	<atom:link href="https://www.dixunblog.cn/tag/python-operator/feed" rel="self" type="application/rss+xml" />
	<link>https://www.dixunblog.cn/tag/python-operator</link>
	<description>致力于打造专业的互联网资讯平台</description>
	<lastBuildDate>Mon, 06 Apr 2026 00:30:05 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://cdn.hyclive.cn/dixunblog/2025/12/cropped-ico-32x32.png</url>
	<title>python-operator归档 - 帝讯博客</title>
	<link>https://www.dixunblog.cn/tag/python-operator</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Python 运算符与表达式详解 &#8211; 进阶篇</title>
		<link>https://www.dixunblog.cn/1567.html</link>
					<comments>https://www.dixunblog.cn/1567.html#respond</comments>
		
		<dc:creator><![CDATA[小编]]></dc:creator>
		<pubDate>Mon, 06 Apr 2026 00:30:05 +0000</pubDate>
				<category><![CDATA[技术教程]]></category>
		<category><![CDATA[Python 教程]]></category>
		<category><![CDATA[python-operator]]></category>
		<category><![CDATA[代码教程]]></category>
		<guid isPermaLink="false">https://www.dixunblog.cn/1567.html</guid>

					<description><![CDATA[<p>欢迎来到今天的 Python 基础教程！今天我们来深入讲解 Python 运算符与表达式。</p>
<p>一、算术运算符</p>
<p>1.1 基本运算<br />
<code class="language-python">a = 10<br />
b = 3</p>
<p>print(a + b)  # 加法：13<br />
print(a - b)  # 减法：7<br />
print(a ...</p>
<p><a href="https://www.dixunblog.cn/1567.html">Python 运算符与表达式详解 &#8211; 进阶篇</a>最先出现在<a href="https://www.dixunblog.cn">帝讯博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p>欢迎来到今天的 Python 基础教程！今天我们来深入讲解 Python 运算符与表达式。</p>
<h2>一、算术运算符</h2>
<h3>1.1 基本运算</h3>
<pre><code class="language-python">a = 10
b = 3

print(a + b)  # 加法：13
print(a - b)  # 减法：7
print(a * b)  # 乘法：30
print(a / b)  # 除法：3.333...
print(a // b) # 整除：3
print(a % b)  # 取余：1
print(a ** b) # 幂运算：1000</code></pre>
<h3>1.2 应用场景</h3>
<pre><code class="language-python"># 计算折扣
price = 100
discount = 0.8
final_price = price * discount

# 判断奇偶
num = 17
if num % 2 == 0:
    print("偶数")
else:
    print("奇数")</code></pre>
<h2>二、比较运算符</h2>
<pre><code class="language-python">x = 5
y = 10

print(x == y)  # 等于：False
print(x != y)  # 不等于：True
print(x &gt; y)   # 大于：False
print(x = 5)  # 大于等于：True
print(y &lt;= 10) # 小于等于：True</code></pre>
<h2>三、逻辑运算符</h2>
<pre><code class="language-python">a = True
b = False

print(a and b)  # 与：False
print(a or b)   # 或：True
print(not a)    # 非：False

# 短路求值
result = False and print("不会执行")
result = True or print("不会执行")</code></pre>
<h2>四、位运算符</h2>
<pre><code class="language-python">a = 60    # 0011 1100
b = 13    # 0000 1101

print(a &amp; b)   # 与：12  (0000 1100)
print(a | b)   # 或：61  (0011 1101)
print(a ^ b)   # 异或：49 (0011 0001)
print(~a)      # 取反：-61
print(a &lt;&gt; 2)  # 右移：15</code></pre>
<h2>五、赋值运算符</h2>
<pre><code class="language-python">x = 10
x += 5   # x = x + 5
x -= 3   # x = x - 3
x *= 2   # x = x * 2
x /= 4   # x = x / 4
x //= 2  # x = x // 2
x %= 3   # x = x % 3
x **= 2  # x = x ** 2</code></pre>
<h2>六、成员运算符</h2>
<pre><code class="language-python">fruits = ["苹果", "香蕉", "橙子"]

print("苹果" in fruits)      # True
print("葡萄" not in fruits)  # True

text = "Hello, Python!"
print("Python" in text)      # True</code></pre>
<h2>七、身份运算符</h2>
<pre><code class="language-python">a = [1, 2, 3]
b = [1, 2, 3]
c = a

print(a == b)    # True（值相等）
print(a is b)    # False（不是同一对象）
print(a is c)    # True（同一对象）
print(a is not b) # True</code></pre>
<h2>八、运算符优先级</h2>
<pre><code class="language-python"># 优先级从高到低
# 1. 括号 ()
# 2. 幂 **
# 3. 正负 +x, -x
# 4. 算术 *, /, //, %
# 5. 算术 +, -
# 6. 比较 ==, !=, &gt;, &lt;
# 7. 逻辑 not, and, or

result = 2 + 3 * 4  # 14。不是 20
result = (2 + 3) * 4  # 20</code></pre>
<h2>九、实战示例</h2>
<pre><code class="language-python"># 计算三角形面积（海伦公式）
import math

a, b, c = 3, 4, 5
s = (a + b + c) / 2
area = math.sqrt(s * (s-a) * (s-b) * (s-c))
print(f"面积：{area}")

# 判断闰年
year = 2024
is_leap = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
print(f"{year}是闰年：{is_leap}")</code></pre>
<h2>十、总结</h2>
<p>掌握运算符是 Python 编程的基础。建议多练习。</p>
<hr>
<p><em>关注我们获取更多 Python 教程！</em></p>
<p><a href="https://www.dixunblog.cn/1567.html">Python 运算符与表达式详解 &#8211; 进阶篇</a>最先出现在<a href="https://www.dixunblog.cn">帝讯博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dixunblog.cn/1567.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
