Master Python’s Basic Operators and Comments with Simple Examples
This tutorial walks through Python’s arithmetic and comparison operators, shows exact code snippets and their outputs, explains why Boolean results appear as True or False, and then introduces single‑line and multi‑line comment syntax with clear demonstrations.
First, the article lists Python’s fundamental arithmetic and comparison operators: + (addition), - (subtraction), * (multiplication), / (division), % (modulo), < (less than), > (greater than), <= (less than or equal), and >= (greater than or equal).
It then asks readers to write the following statements into a program and observe the results:
print("加法--二加九--", 2+9)
print("减法--二减四--", 2-4)
print("乘法--二乘一--", 2*1)
print("除法--五除以三--", 5/3)
print("取余--五除以四取余数--", 5%4)
print("大于号--三大于二--", 3>2)
print("小于号--三小于二--", 3<2)
print("大于等于号--二大于等于二--", 2>=2)
print("小于等于号--五小于等于四--", 5<=4)Running the program produces the exact output shown below, demonstrating both numeric results and Boolean values:
加法--二加九-- 11
减法--二减四-- -2
乘法--二乘一-- 2
除法--五除以三-- 1.6666666666666667
取余--五除以四取余数-- 1
大于号--三大于二-- True
小于号--三小于二-- False
大于等于号--二大于等于二-- True
小于等于号--五小于等于四-- FalseThe article explains that comparison operators return Boolean values ( True or False) indicating whether the relationship holds, while arithmetic operators return the computed numeric result.
Next, the tutorial introduces comments. A single‑line comment starts with #, which tells the interpreter to ignore the rest of the line. The example demonstrates this:
#print("我是不被执行的代码")
print("我是被执行的代码")When executed, only the second line runs, producing:
我是被执行的代码For multi‑line comments, Python accepts either three single quotes ( ''' ... ''') or three double quotes ( """ ... """) to enclose a block of text that the interpreter ignores. The article encourages readers to experiment with these forms.
Finally, a screenshot of the program’s output is provided for reference:
AI Large-Model Wave and Transformation Guide
Focuses on the latest large-model trends, applications, technical architectures, and related information.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
