{"id":1020,"date":"2023-03-24T09:47:07","date_gmt":"2023-03-24T01:47:07","guid":{"rendered":""},"modified":"2023-03-24T09:47:07","modified_gmt":"2023-03-24T01:47:07","slug":"Python \u8fd0\u7b97\u7b26","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1020.html","title":{"rendered":"Python \u8fd0\u7b97\u7b26"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

Python \u8fd0\u7b97\u7b26<\/h1>\n

\u641e\u61c2Python\u5e38\u7528\u7684\u8fd0\u7b97\u7b26<\/span>\n <\/div>\n

\n \u8fd0\u7b97\u7b26\u7528\u4e8e\u5bf9\u53d8\u91cf\u548c\u503c\u6267\u884c\u64cd\u4f5c\u3002\u6bd4\u5982\uff1a 1 +2 = 3 \u4e2d\uff0c1 \u548c 2 \u88ab\u79f0\u4e3a\u64cd\u4f5c\u6570\uff0c\"+\" \u79f0\u4e3a\u8fd0\u7b97\u7b26\u3002\n <\/div>\n
\n Python\u652f\u6301\u8fd0\u7b97\u7b26\u7684\u7c7b\u578b\u5982\u4e0b:\n <\/div>\n

\u7b97\u672f\u8fd0\u7b97\u7b26<\/span>
\n \u8d4b\u503c\u8fd0\u7b97\u7b26<\/span>
\n \u6bd4\u8f83\u8fd0\u7b97\u7b26<\/span>
\n \u903b\u8f91\u8fd0\u7b97\u7b26<\/span>
\n \u8eab\u4efd\u8fd0\u7b97\u7b26<\/span>
\n \u6210\u5458\u8fd0\u7b97\u7b26<\/span>
\n \u4f4d\u8fd0\u7b97\u7b26<\/span> <\/p>\n

\n \u4e0b\u9762\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u3002\n <\/div>\n

\u7b97\u672f\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n\n\n\n\n\n\n\n
\u8fd0\u7b97\u7b26<\/td>\n\u63cf\u8ff0<\/td>\n\u5b9e\u4f8b<\/td>\n\u7ed3\u679c<\/td>\n<\/tr>\n
+<\/td>\n\u52a0\uff08\u4e24\u4e2a\u6570\u76f8\u52a0\uff09<\/td>\n1 + 2<\/td>\n3<\/td>\n<\/tr>\n
-<\/td>\n\u51cf\uff08\u4e24\u4e2a\u6570\u76f8\u51cf\uff09<\/td>\n2 - 1<\/td>\n1<\/td>\n<\/tr>\n
*<\/td>\n\u4e58\uff08\u4e24\u4e2a\u6570\u76f8\u4e58\uff09<\/td>\n1 * 2<\/td>\n2<\/td>\n<\/tr>\n
\/<\/td>\n\u9664\uff08\u4e24\u4e2a\u6570\u76f8\u9664\uff09<\/td>\n6 \/ 3<\/td>\n2<\/td>\n<\/tr>\n
\/\/<\/td>\n\u53d6\u6574\u9664\uff08\u5411\u4e0b\u53d6\u63a5\u8fd1\u5546\u7684\u6574\u6570\uff09<\/td>\n7\/\/2<\/td>\n3<\/td>\n<\/tr>\n
%<\/td>\n\u53d6\u6a21\uff08\u8fd4\u56de\u9664\u6cd5\u7684\u4f59\u6570\uff09<\/td>\n 5 % 3<\/td>\n2<\/td>\n<\/tr>\n
**<\/td>\n\u5e42\uff08\u8fd4\u56dex\u7684y\u6b21\u5e42\uff09<\/td>\n2**4<\/td>\n16<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n \u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u7b97\u672f\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a\n <\/div>\n
\n
 a = 1<\/span>
b = 2<\/span>
c = 6<\/span>
d = 7<\/span>
x = a + b<\/span>
print(\"a + b =\", x<\/span>)
x = b - a<\/span>
print(\"b - a =\", x<\/span>)
x = a * b<\/span>
print(\"a * b=\", x<\/span>)
x = c \/ b<\/span>
print(\"c \/ b=\", x<\/span>)
x = d \/\/ b<\/span>
print(\"d \/\/ b=\", x<\/span>)
x = d % b<\/span>
print(\"d % b =\", x<\/span>)
x = b**c<\/span>
print(\"b**c=\", c<\/span>) <\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
a + b = 3<\/span> \n
\nb - a = 1<\/span> \n
\na * b = 2<\/span> \n
\nd \/\/ b = 3<\/span> \n
\nd % b = 1<\/span> \n
\nb**c= 64<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u8d4b\u503c\u8fd0\u7b97\u7b26<\/h2>\n
\n \u8d4b\u503c\u8fd0\u7b97\u7b26\u7528\u6765\u628a\u53f3\u4fa7\u7684\u503c\u4f20\u9012\u7ed9\u5de6\u4fa7\u7684\u53d8\u91cf\uff0c\u8d4b\u503c\u8fd0\u7b97\u7b26\u662f\u7b49\u53f7=\uff0c\u7ed3\u5408\u5176\u5b83\u8fd0\u7b97\u7b26\u8fd8\u80fd\u6269\u5c55\u51fa\u66f4\u5f3a\u5927\u7684\u8d4b\u503c\u8fd0\u7b97\u7b26\u3002\n <\/div>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\u8fd0\u7b97\u7b26<\/td>\n\u8bf4 \u660e<\/td>\n\u7528\u6cd5\u4e3e\u4f8b<\/td>\n \u7b49\u4ef7\u5f62\u5f0f<\/td>\n<\/tr>\n
= <\/td>\n\u7b80\u5355\u7684\u8d4b\u503c\u8fd0\u7b97\u7b26 <\/td>\nx = y <\/td>\nx = y<\/td>\n<\/tr>\n
+= <\/td>\n\u52a0\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\n x += y <\/td>\nx = x + y<\/td>\n<\/tr>\n
-= <\/td>\n\u51cf\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26 <\/td>\nx -= y <\/td>\nx = x - y<\/td>\n<\/tr>\n
*= <\/td>\n\u4e58\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\nx *= y <\/td>\nx = x * y<\/td>\n<\/tr>\n
\/= <\/td>\n\u9664\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\n x \/= y <\/td>\nx = x \/ y<\/td>\n<\/tr>\n
%= <\/td>\n\u53d6\u4f59\u6570\u8d4b\u503c\u8fd0\u7b97\u7b26 <\/td>\nx %= y <\/td>\nx = x % y<\/td>\n<\/tr>\n
**= <\/td>\n\u5e42\u8d4b\u503c\u8fd0\u7b97\u7b26 <\/td>\nx **= y <\/td>\nx = x ** y<\/td>\n<\/tr>\n
\/\/= <\/td>\n\u53d6\u6574\u6570\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\n x \/\/= y <\/td>\nx = x \/\/ y<\/td>\n<\/tr>\n
&= <\/td>\n\u6309\u4f4d\u4e0e\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\nx &= y <\/td>\nx = x & y<\/td>\n<\/tr>\n
|= <\/td>\n\u6309\u4f4d\u6216\u8d4b\u503c<\/td>\nx |= y <\/td>\nx = x | y<\/td>\n<\/tr>\n
^= <\/td>\n\u6309\u4f4d\u5f02\u6216\u8d4b\u503c\u8fd0\u7b97\u7b26 <\/td>\nx ^= y <\/td>\nx = x ^ y<\/td>\n<\/tr>\n
<<= <\/td>\n\u5de6\u79fb\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\nx <<= y <\/td>\nx = x << y\uff0c\u8fd9\u91cc\u7684 y \u6307\u7684\u662f\u5de6\u79fb\u7684\u4f4d\u6570<\/td>\n<\/tr>\n
>>= <\/td>\n\u53f3\u79fb\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\nx >>= y <\/td>\nx = x >> y\uff0c\u8fd9\u91cc\u7684 y \u6307\u7684\u662f\u53f3\u79fb\u7684\u4f4d\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n \u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u8d4b\u503c\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a\n <\/div>\n
\n
 a = 12<\/span>
b = 25<\/span>
c = a + b<\/span>
print(\"a + b =\", c<\/span>)
c += a<\/span>
print(\"c = \", c<\/span>)
c *= a<\/span>
print(\"c = \", c<\/span>)
c \/= a<\/span>
print(\"c = \", c<\/span>)
c %= a<\/span>
print(\"c = \", c<\/span>)
c **= a<\/span>
print(\"c = \", c<\/span>)
c\/\/= a<\/span>
print(\"c = \", c<\/span>) <\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
a + b = 37<\/span> \n
\nc += a : 49<\/span> \n
\nc *= a : 588<\/span> \n
\nc \/= a : 49<\/span> \n
\nc %= a : 1<\/span> \n
\nc **= a : 1<\/span> \n
\nc\/\/= a : 0<\/span> \n
<\/code><\/pre>\n<\/p><\/div>\n

\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h2>\n
\n \u6bd4\u8f83\u8fd0\u7b97\u7b26\u4e5f\u79f0\u5173\u7cfb\u8fd0\u7b97\u7b26\uff0c\u7528\u4e8e\u5bf9\u5e38\u91cf\u3001\u53d8\u91cf\u6216\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u8fdb\u884c\u5927\u5c0f\u6bd4\u8f83\uff0c\u6bd4\u8f83\u7684\u7ed3\u679c\u53ea\u6709True\uff08\u771f\uff09\u6216False\uff08\u5047\uff09\u4e24\u79cd\u72b6\u6001\u3002\n <\/div>\n\n\n\n\n\n\n\n\n\n
\u8fd0\u7b97\u7b26 <\/td>\n\u63cf\u8ff0<\/td>\n\u5b9e\u4f8b <\/td>\n\u7ed3\u679c<\/td>\n<\/tr>\n
==<\/td>\n\u7b49\u4e8e\uff08\u6bd4\u8f83\u5bf9\u8c61\u662f\u5426\u76f8\u7b49\uff09 <\/td>\n1 == 2 <\/td>\nFalse<\/td>\n<\/tr>\n
!=<\/td>\n\u4e0d\u7b49\u4e8e\uff08\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u4e0d\u76f8\u7b49\uff09<\/td>\n 1 != 2 <\/td>\nTrue<\/td>\n<\/tr>\n
><\/td>\n\u5927\u4e8e\uff08\u8fd4\u56dex\u662f\u5426\u5927\u4e8ey\uff09<\/td>\n1 > 2 <\/td>\nFalse<\/td>\n<\/tr>\n
<<\/td>\n\u5c0f\u4e8e\uff08\u8fd4\u56dex\u662f\u5426\u5c0f\u4e8ey\uff09<\/td>\n1 < 2 <\/td>\nTrue<\/td>\n<\/tr>\n
>=<\/td>\n\u5927\u4e8e\u7b49\u4e8e\uff08\u8fd4\u56dex\u662f\u5426\u5927\u4e8e\u7b49\u4e8ey\uff09<\/td>\n1 >= 2 <\/td>\nFalse<\/td>\n<\/tr>\n
<=<\/td>\n\u5c0f\u4e8e\u7b49\u4e8e\uff08\u8fd4\u56dex\u662f\u5426\u5c0f\u4e8e\u7b49\u4e8ey\uff09<\/td>\n1 <= 2 <\/td>\nTrue<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n
 a = 1<\/span>
b = 2<\/span>
if<\/span> ( a == b ):
 print(\"a \u7b49\u4e8e b\"<\/span>)
else:<\/span>
 print(\"a \u4e0d\u7b49\u4e8e b\"<\/span>)
if<\/span> ( a != b ):
 print(\"a \u4e0d\u7b49\u4e8e b\"<\/span>)
else:<\/span>
 print(\"a \u7b49\u4e8e b\"<\/span>)
if<\/span> ( a < b ):
 print(\"a \u5c0f\u4e8e b\"<\/span>)
else:<\/span>
 print(\"a \u5927\u4e8e\u7b49\u4e8e b\"<\/span>)
if<\/span> ( a > b ):
 print(\"a \u5927\u4e8e b\"<\/span>)
else:<\/span>
 print(\"a \u5c0f\u4e8e\u7b49\u4e8e b\"<\/span>)
if<\/span> ( a >= b ):
 print(\"a \u5927\u4e8e\u7b49\u4e8e b\"<\/span>)
else:<\/span>
 print(\"a \u5c0f\u4e8e b\"<\/span>)
if<\/span> ( a <= b ):
 print(\"a \u5c0f\u4e8e\u7b49\u4e8e b\"<\/span>)
else:<\/span>
 print(\"a \u5927\u4e8e b\"<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
a \u4e0d\u7b49\u4e8e b<\/span> \n
\na \u4e0d\u7b49\u4e8e b<\/span> \n
\na \u5c0f\u4e8e b<\/span> \n
\na \u5c0f\u4e8e\u7b49\u4e8e b<\/span> \n
\na \u5c0f\u4e8eb<\/span> \n
\na \u5c0f\u4e8e\u7b49\u4e8e b<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u903b\u8f91\u8fd0\u7b97\u7b26<\/h2>\n
\n \u903b\u8f91\u8fd0\u7b97\u7b26\u7528\u4e8e\u7ec4\u5408\u6761\u4ef6\u8bed\u53e5\uff1a\n <\/div>\n\n\n\n\n\n\n
\u8fd0\u7b97\u7b26<\/td>\n\u8868\u8fbe\u5f0f<\/td>\n\u63cf\u8ff0<\/td>\n\u5b9e\u4f8b<\/td>\n\u7ed3\u679c<\/td>\n<\/tr>\n
and <\/td>\nx and y<\/td>\n\u4e14\uff0c\u4e24\u4e2a\u503c\u90fd\u4e3a\u771f\u8fd4\u56de\u771f<\/td>\nTrue and True<\/td>\nTrue<\/td>\n<\/tr>\n
or <\/td>\nx or y <\/td>\n\u6216\uff0c\u6709\u4e00\u4e2a\u503c\u4e3a\u771f\u8fd4\u56de\u771f<\/td>\nTrue or False<\/td>\nTrue<\/td>\n<\/tr>\n
not <\/td>\nnot x <\/td>\n\u975e\uff0c\u76f8\u53cd\uff0c\u503c\u4e3a\u771f\u8fd4\u56de\u5047<\/td>\n not True<\/td>\nFalse<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n
 print(100 and 200<\/span>)
print(True and False<\/span>)
print(not (True and False)<\/span>)
print(\"\" or \"lidihuo\"<\/span>)
print(1 or \"lidihuo\"<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
200<\/span> \n
\nFalse<\/span> \n
\nTrue<\/span> \n
\nlidihuo<\/span> \n
\n1<\/span> \n
<\/code><\/pre>\n<\/p><\/div>\n
\n \u6ce8\u610f\uff1a<\/span>\u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u7ed3\u679c\u5e76\u975e\u53ea\u6709True\u548cFalse\n <\/div>\n

\u8eab\u4efd\u8fd0\u7b97\u7b26<\/h2>\n
\n \u8eab\u4efd\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u5bf9\u8c61\u662f\u5426\u4e3a\u540c\u4e00\u4e2a\u5bf9\u8c61\u3002\n <\/div>\n\n\n\n\n\n
\u8fd0\u7b97\u7b26<\/td>\n\u63cf\u8ff0<\/td>\n\u5b9e\u4f8b<\/td>\n\u7ed3\u679c<\/td>\n<\/tr>\n
is<\/td>\n\u5f15\u7528\u81ea\u4e00\u4e2a\u5bf9\u8c61\u8fd4\u56deTrue<\/td>\n1 is \u20181\u2019<\/td>\nFalse<\/td>\n<\/tr>\n
is not<\/td>\n\u4e0d\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\u8fd4\u56deTrue 1<\/td>\nis not \u20181\u2019<\/td>\nTrue<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n
 a = 1<\/span>
b = 1<\/span>
print(a is b<\/span>)
print(id(a) == id(b)<\/span>) # id() \u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u5185\u5b58\u5730\u5740<\/span> <\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
True<\/span> \n
\nTrue<\/span> \n
<\/code><\/pre>\n<\/p><\/div>\n
\n \u6ce8\u610f\uff1a<\/span>is \u4e0e == \u533a\u522b\u662fis \u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u53d8\u91cf\u5f15\u7528\u5bf9\u8c61\u662f\u5426\u4e3a\u540c\u4e00\u4e2a\uff0c == \u7528\u4e8e\u5224\u65ad\u5f15\u7528\u53d8\u91cf\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002\n <\/div>\n

\u6210\u5458\u8fd0\u7b97\u7b26<\/h2>\n
\n \u6210\u5458\u8d44\u683c\u8fd0\u7b97\u7b26\u7528\u4e8e\u6d4b\u8bd5\u5e8f\u5217\u662f\u5426\u5728\u5bf9\u8c61\u4e2d\u51fa\u73b0\n <\/div>\n\n\n\n\n\n
\u8fd0\u7b97\u7b26<\/td>\n\u63cf\u8ff0<\/td>\n\u5b9e\u4f8b<\/td>\n<\/tr>\n
in<\/td>\n\u5982\u679c\u5bf9\u8c61\u4e2d\u5b58\u5728\u5177\u6709\u6307\u5b9a\u503c\u7684\u5e8f\u5217\uff0c\u5219\u8fd4\u56de True\u3002<\/td>\nx in y<\/td>\n<\/tr>\n
not in<\/td>\n\u5982\u679c\u5bf9\u8c61\u4e2d\u4e0d\u5b58\u5728\u5177\u6709\u6307\u5b9a\u503c\u7684\u5e8f\u5217\uff0c\u5219\u8fd4\u56de True\u3002<\/td>\nx not in y <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n
 a = 1<\/span>
b = 10<\/span>
list = [1, 2, 3, 4, 5 ]<\/span>
print(a in list<\/span>)
print(b not in list<\/span>) <\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
True<\/span> \n
\nTrue<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u4f4d\u8fd0\u7b97\u7b26<\/h2>\n
\n \u4f4d\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\uff08\u4e8c\u8fdb\u5236\uff09\u6570\u5b57\n <\/div>\n\n\n\n\n\n\n\n\n\n
\u8fd0\u7b97\u7b26<\/td>\n\u63cf\u8ff0<\/td>\n\u5b9e\u4f8b<\/td>\n<\/tr>\n
&<\/td>\nAND,\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e24\u4e2a\u503c,\u5982\u679c\u4e24\u4e2a\u76f8\u5e94\u4f4d\u90fd\u4e3a1,\u5219\u8be5\u4f4d\u7684\u7ed3\u679c\u4e3a1,\u5426\u5219\u4e3a0<\/td>\n(a & b) \u8f93\u51fa\u7ed3\u679c 12 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0000 1100<\/td>\n<\/tr>\n
|<\/td>\nOR,\u53ea\u8981\u5bf9\u5e94\u7684\u4e8c\u4e2a\u4e8c\u8fdb\u4f4d\u6709\u4e00\u4e2a\u4e3a1\u65f6\uff0c\u7ed3\u679c\u4f4d\u5c31\u4e3a1\u3002<\/td>\n (a | b) \u8f93\u51fa\u7ed3\u679c 61 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0011 1101<\/td>\n<\/tr>\n
^<\/td>\nXOR,\u5f53\u4e24\u5bf9\u5e94\u7684\u4e8c\u8fdb\u4f4d\u76f8\u5f02\u65f6\uff0c\u7ed3\u679c\u4e3a1 <\/td>\n(a ^ b) \u8f93\u51fa\u7ed3\u679c 49 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0011 0001<\/td>\n<\/tr>\n
~<\/td>\nNOT,\u5bf9\u6570\u636e\u7684\u6bcf\u4e2a\u4e8c\u8fdb\u5236\u4f4d\u53d6\u53cd,\u5373\u628a1\u53d8\u4e3a0,\u628a0\u53d8\u4e3a1\u3002<\/td>\n (~a ) \u8f93\u51fa\u7ed3\u679c -61 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 1100 0011\uff0c \u5728\u4e00\u4e2a\u6709\u7b26\u53f7\u4e8c\u8fdb\u5236\u6570\u7684\u8865\u7801\u5f62\u5f0f\u3002<\/td>\n<\/tr>\n
<<<\/td>\n\u5de6\u79fb\u52a8\u8fd0\u7b97\u7b26\uff1a\u8fd0\u7b97\u6570\u7684\u5404\u4e8c\u8fdb\u4f4d\u5168\u90e8\u5de6\u79fb\u82e5\u5e72\u4f4d\u3002<\/td>\n a << 2 \u8f93\u51fa\u7ed3\u679c 240 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 1111 0000<\/td>\n<\/tr>\n
>><\/td>\n\u53f3\u79fb\u52a8\u8fd0\u7b97\u7b26\uff1a\u628a\">>\"\u5de6\u8fb9\u7684\u8fd0\u7b97\u6570\u7684\u5404\u4e8c\u8fdb\u4f4d\u5168\u90e8\u53f3\u79fb\u82e5\u5e72\u4f4d\u3002<\/td>\na >> 2 \u8f93\u51fa\u7ed3\u679c 15 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0000 1111<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n
 a = 60<\/span> # 60 = 0011 1100<\/span>
b = 13<\/span> # 13 = 0000 1101<\/span>
c = 0<\/span>
c = a & b<\/span> # 12 = 0000 1100<\/span>
print(\"1 - c \u7684\u503c\u4e3a\uff1a\", c<\/span>)
c = a | b<\/span> # 61 = 0011 1101<\/span>
print(\"2 - c \u7684\u503c\u4e3a\uff1a\", c<\/span>)
c = a ^ b<\/span> # 49 = 0011 0001<\/span>
print(\"3 - c \u7684\u503c\u4e3a\uff1a\", c<\/span>)
c = ~a<\/span> # -61 = 1100 0011<\/span>
print(\"4 - c \u7684\u503c\u4e3a\uff1a\", c<\/span>)
c = a << 2<\/span> # 240 = 1111 0000<\/span>
print(\"5 - c \u7684\u503c\u4e3a\uff1a\", c<\/span>)
c = a >> 2<\/span> # 15 = 0000 1111<\/span>
print(\"6 - c \u7684\u503c\u4e3a\uff1a\", c<\/span>) <\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
1 - c \u7684\u503c\u4e3a\uff1a 12<\/span> \n
\n2 - c \u7684\u503c\u4e3a\uff1a 61<\/span> \n
\n3 - c \u7684\u503c\u4e3a\uff1a 49<\/span> \n
\n4 - c \u7684\u503c\u4e3a\uff1a -61<\/span> \n
\n5 - c \u7684\u503c\u4e3a\uff1a 240<\/span> \n
\n6 - c \u7684\u503c\u4e3a\uff1a 15<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7<\/h2>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\u8fd0\u7b97\u7b26<\/td>\n\u63cf\u8ff0<\/td>\n<\/tr>\n
**<\/td>\n\u6307\u6570 (\u6700\u9ad8\u4f18\u5148\u7ea7)<\/td>\n<\/tr>\n
~ + -<\/td>\n\u6309\u4f4d\u7ffb\u8f6c, \u4e00\u5143\u52a0\u53f7\u548c\u51cf\u53f7 (\u6700\u540e\u4e24\u4e2a\u7684\u65b9\u6cd5\u540d\u4e3a +@ \u548c -@)<\/td>\n<\/tr>\n
* \/ % \/\/<\/td>\n\u4e58\uff0c\u9664\uff0c\u6c42\u4f59\u6570\u548c\u53d6\u6574\u9664<\/td>\n<\/tr>\n
+ -<\/td>\n\u52a0\u6cd5\u51cf\u6cd5<\/td>\n<\/tr>\n
>> <<<\/td>\n\u53f3\u79fb\uff0c\u5de6\u79fb\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n
&<\/td>\n\u4f4d 'AND'<\/td>\n<\/tr>\n
^ |<\/td>\n\u4f4d\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n
<= < > >=<\/td>\n\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n
== !=<\/td>\n\u7b49\u4e8e\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n
= %= \/= \/\/= -= += *= **=<\/td>\n\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n
is is not<\/td>\n\u8eab\u4efd\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n
in not in<\/td>\n\u6210\u5458\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n
not and or<\/td>\n\u903b\u8f91\u8fd0\u7b97\u7b26<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n
 a = 20<\/span>
b = 10<\/span>
c = 15<\/span>
d = 5<\/span>
e = (a + b) * c \/ d;<\/span>
print('(a + b) * c \/ d: ',e<\/span>)
e = (((a + b) * c) \/ d;<\/span>
print('(((a + b) * c) \/ d: ',e<\/span>)
e = (a + b) * (c \/ d);<\/span>
print('a + b) * (c \/ d: ',e<\/span>)
e = a + (b * c) \/ d;<\/span>
print('a + (b * c) \/ d: ',e<\/span>) <\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
(a + b) * c \/ d: 90)<\/span> \n
\n(((a + b) * c) \/ d: 90)<\/span> \n
\na + b) * (c \/ d: 90)<\/span> \n
\na + (b * c) \/ d: 50)<\/span><\/code><\/pre>\n<\/p><\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Python \u8fd0\u7b97\u7b26zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[126],"tags":[],"class_list":["post-1020","post","type-post","status-publish","format-standard","hentry","category-python3"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1020"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1020"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1020\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}