{"id":1148990,"date":"2025-01-13T16:44:13","date_gmt":"2025-01-13T08:44:13","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1148990.html"},"modified":"2025-01-13T16:44:15","modified_gmt":"2025-01-13T08:44:15","slug":"python2-7-%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1148990.html","title":{"rendered":"python2.7 \u5982\u4f55\u8fd0\u884c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25175719\/b5ee5b01-85f8-43b8-83a7-6250e496c0d5.webp\" alt=\"python2.7 \u5982\u4f55\u8fd0\u884c\" \/><\/p>\n<p><p> <strong>\u8981\u8fd0\u884cPython 2.7\u7a0b\u5e8f\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Python 2.7\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u7f16\u5199Python\u811a\u672c\u3001\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u811a\u672c\u3002<\/strong> \u5176\u4e2d\uff0c\u5b89\u88c5Python 2.7\u662f\u6700\u5173\u952e\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u5982\u679c\u6ca1\u6709\u6b63\u786e\u5b89\u88c5Python 2.7\uff0c\u5176\u4ed6\u6b65\u9aa4\u90fd\u65e0\u6cd5\u8fdb\u884c\u3002\u4e3a\u4e86\u8be6\u7ec6\u63cf\u8ff0\u8fd9\u4e2a\u6b65\u9aa4\uff0c\u8bf7\u7ee7\u7eed\u9605\u8bfb\u3002<\/p>\n<\/p>\n<p><h3>\u5b89\u88c5Python 2.7<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/downloads\/release\/python-2718\/%EF%BC%89%E4%B8%8B%E8%BD%BDPython\">https:\/\/www.python.org\/downloads\/release\/python-2718\/\uff09\u4e0b\u8f7dPython<\/a> 2.7\u7684\u5b89\u88c5\u5305\u3002\u9009\u62e9\u4e0e\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u5339\u914d\u7684\u7248\u672c\uff08Windows\u3001Mac OS X\u3001Linux\u7b49\uff09\uff0c\u7136\u540e\u6839\u636e\u4e0b\u8f7d\u7684\u5b89\u88c5\u5305\u6267\u884c\u5b89\u88c5\u7a0b\u5e8f\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u9009\u62e9\u5b89\u88c5\u8def\u5f84<\/strong>\uff1a\u5b89\u88c5\u7a0b\u5e8f\u4f1a\u9ed8\u8ba4\u9009\u62e9\u4e00\u4e2a\u5b89\u88c5\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u63a5\u53d7\u9ed8\u8ba4\u9009\u9879\u6216\u8005\u9009\u62e9\u4e00\u4e2a\u81ea\u5b9a\u4e49\u8def\u5f84\u3002<\/li>\n<li><strong>\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\u5728\u5b89\u88c5\u7684\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u9009\u62e9\u5c06Python\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u7684\u9009\u9879\uff0c\u8fd9\u6837\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u547d\u4ee4\u3002<\/li>\n<li><strong>\u5b89\u88c5\u540e\u9a8c\u8bc1<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff08Windows\u4e0b\u662fcmd\uff0cMac\u548cLinux\u4e0b\u662fTerminal\uff09\uff0c\u8f93\u5165<code>python --version<\/code>\uff0c\u5982\u679c\u663e\u793a<code>Python 2.7.x<\/code>\uff08x\u8868\u793a\u5177\u4f53\u7684\u5c0f\u7248\u672c\u53f7\uff09\uff0c\u5219\u8868\u793a\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<\/ol>\n<p><h3>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u672a\u9009\u62e9\u81ea\u52a8\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\uff0c\u4f60\u9700\u8981\u624b\u52a8\u6dfb\u52a0\u3002\u5728Windows\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6dfb\u52a0Python\u5230\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u53f3\u952e\u70b9\u51fb\u201c\u8ba1\u7b97\u673a\u201d\u6216\u8005\u201c\u6b64\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u5728\u7cfb\u7edf\u53d8\u91cf\u4e2d\u627e\u5230\u540d\u4e3a\u201cPath\u201d\u7684\u53d8\u91cf\uff0c\u9009\u62e9\u5b83\u5e76\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/li>\n<li>\u5728\u53d8\u91cf\u503c\u7684\u672b\u5c3e\u6dfb\u52a0Python\u7684\u5b89\u88c5\u8def\u5f84\uff08\u4f8b\u5982\uff1a<code>C:\\Python27<\/code>\uff09\uff0c\u7528\u5206\u53f7\u9694\u5f00\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u3002<\/li>\n<\/ol>\n<p><p>\u5728Mac\u548cLinux\u4e2d\uff0c\u4f60\u53ef\u4ee5\u7f16\u8f91\u7ec8\u7aef\u7684\u914d\u7f6e\u6587\u4ef6\uff08\u5982<code>.bashrc<\/code>\u3001<code>.bash_profile<\/code>\u6216\u8005<code>.zshrc<\/code>\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">export PATH=&quot;\/path\/to\/python2.7:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u6587\u4ef6\u5e76\u8fd0\u884c<code>source ~\/.bashrc<\/code>\uff08\u6216\u76f8\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\uff09\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/p>\n<\/p>\n<p><h3>\u7f16\u5199Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\uff0c\u4f8b\u5982<code>hello.py<\/code>\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, Python 2.7!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u6765\u7f16\u5199\u8fd9\u4e2a\u811a\u672c\uff0c\u4f8b\u5982Notepad++\u3001Sublime Text\u3001VS Code\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u5bfc\u822a\u5230\u4fdd\u5b58\u811a\u672c\u7684\u76ee\u5f55\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u770b\u5230\u8f93\u51fa<code>Hello, Python 2.7!<\/code>\uff0c\u5219\u8bf4\u660e\u4f60\u7684Python\u811a\u672c\u8fd0\u884c\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u5b89\u88c5Python 2.7<\/h2>\n<\/p>\n<p><h3>\u5728Windows\u4e0a\u5b89\u88c5Python 2.7<\/h3>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e0a\u5b89\u88c5Python 2.7\u76f8\u5bf9\u7b80\u5355\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u9002\u5408Windows\u7684\u5b89\u88c5\u5305\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb\u5b89\u88c5\u5305\u5f00\u59cb\u5b89\u88c5\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u9009\u62e9\u5c06Python\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u7684\u9009\u9879\uff0c\u8fd9\u6837\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><h4>\u4e0b\u8f7d\u4e0e\u5b89\u88c5\u6b65\u9aa4<\/h4>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u8bbf\u95eePython\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"https:\/\/www.python.org\/downloads\/release\/python-2718\/\">https:\/\/www.python.org\/downloads\/release\/python-2718\/<\/a><\/li>\n<li>\u4e0b\u8f7d\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\uff08\u4f8b\u5982\uff0cWindows x86 MSI Installer\uff09\u3002<\/li>\n<li>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb\u5b89\u88c5\u5305\u5f00\u59cb\u5b89\u88c5\u3002<\/li>\n<li>\u5728\u5b89\u88c5\u5411\u5bfc\u4e2d\uff0c\u9009\u62e9\u201cAdd Python to PATH\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201cInstall Now\u201d\u3002<\/li>\n<li>\u7b49\u5f85\u5b89\u88c5\u5b8c\u6210\u3002<\/li>\n<\/ol>\n<p><h4>\u9a8c\u8bc1\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u770b\u5230\u7c7b\u4f3c\u4e8e<code>Python 2.7.18<\/code>\u7684\u8f93\u51fa\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u5728Mac OS\u4e0a\u5b89\u88c5Python 2.7<\/h3>\n<\/p>\n<p><p>Mac OS\u901a\u5e38\u81ea\u5e26Python 2.7\uff0c\u4f46\u7248\u672c\u53ef\u80fd\u4e0d\u662f\u6700\u65b0\u7684\u3002\u5982\u679c\u9700\u8981\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python 2.7\uff0c\u53ef\u4ee5\u4f7f\u7528Homebrew\u6765\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528Homebrew\u5b89\u88c5Python 2.7<\/h4>\n<\/p>\n<ol>\n<li>\u6253\u5f00Terminal\u3002<\/li>\n<li>\u5b89\u88c5Homebrew\uff08\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff09\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">\/bin\/bash -c &quot;$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u4f7f\u7528Homebrew\u5b89\u88c5Python 2.7\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">brew install python@2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u9a8c\u8bc1\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u770b\u5230\u7c7b\u4f3c\u4e8e<code>Python 2.7.18<\/code>\u7684\u8f93\u51fa\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u5728Linux\u4e0a\u5b89\u88c5Python 2.7<\/h3>\n<\/p>\n<p><p>\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u81ea\u5e26Python 2.7\uff0c\u4f46\u5982\u679c\u9700\u8981\u7279\u5b9a\u7248\u672c\u6216\u8005\u91cd\u65b0\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5728Ubuntu\u6216Debian\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python 2.7\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">sudo apt-get update<\/p>\n<p>sudo apt-get install python2.7<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728CentOS\u6216Fedora\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">sudo yum install python27<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u9a8c\u8bc1\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u770b\u5230\u7c7b\u4f3c\u4e8e<code>Python 2.7.18<\/code>\u7684\u8f93\u51fa\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h2>\n<\/p>\n<p><p>\u73af\u5883\u53d8\u91cf\u7684\u8bbe\u7f6e\u5bf9\u4e8e\u80fd\u591f\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u547d\u4ee4\u81f3\u5173\u91cd\u8981\u3002\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u672a\u9009\u62e9\u81ea\u52a8\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\uff0c\u4f60\u9700\u8981\u624b\u52a8\u6dfb\u52a0\u3002<\/p>\n<\/p>\n<p><h3>\u5728Windows\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<ol>\n<li>\u53f3\u952e\u70b9\u51fb\u201c\u8ba1\u7b97\u673a\u201d\u6216\u8005\u201c\u6b64\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u5728\u7cfb\u7edf\u53d8\u91cf\u4e2d\u627e\u5230\u540d\u4e3a\u201cPath\u201d\u7684\u53d8\u91cf\uff0c\u9009\u62e9\u5b83\u5e76\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/li>\n<li>\u5728\u53d8\u91cf\u503c\u7684\u672b\u5c3e\u6dfb\u52a0Python\u7684\u5b89\u88c5\u8def\u5f84\uff08\u4f8b\u5982\uff1a<code>C:\\Python27<\/code>\uff09\uff0c\u7528\u5206\u53f7\u9694\u5f00\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u3002<\/li>\n<\/ol>\n<p><h3>\u5728Mac\u548cLinux\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u7f16\u8f91\u7ec8\u7aef\u7684\u914d\u7f6e\u6587\u4ef6\uff08\u5982<code>.bashrc<\/code>\u3001<code>.bash_profile<\/code>\u6216\u8005<code>.zshrc<\/code>\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">export PATH=&quot;\/path\/to\/python2.7:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u6587\u4ef6\u5e76\u8fd0\u884c<code>source ~\/.bashrc<\/code>\uff08\u6216\u76f8\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\uff09\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u7f16\u5199Python\u811a\u672c<\/h2>\n<\/p>\n<p><p>\u7f16\u5199Python\u811a\u672c\u662f\u5b66\u4e60\u548c\u4f7f\u7528Python\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u6765\u7f16\u5199Python\u811a\u672c\uff0c\u4f8b\u5982Notepad++\u3001Sublime Text\u3001VS Code\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>hello.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, Python 2.7!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4fdd\u5b58Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5c06\u6587\u4ef6\u4fdd\u5b58\u5230\u4e00\u4e2a\u4f60\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u7684\u76ee\u5f55\u4e2d\uff0c\u4f8b\u5982\u684c\u9762\u6216\u8005\u6587\u6863\u6587\u4ef6\u5939\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u811a\u672c<\/h2>\n<\/p>\n<p><p>\u8fd0\u884cPython\u811a\u672c\u662f\u9a8c\u8bc1\u4f60\u73af\u5883\u8bbe\u7f6e\u548c\u811a\u672c\u7f16\u5199\u662f\u5426\u6b63\u786e\u7684\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u5728Windows\u4e0a\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff08\u6309\u4e0bWindows\u952e+R\uff0c\u8f93\u5165cmd\u5e76\u56de\u8f66\uff09\u3002<\/li>\n<li>\u5bfc\u822a\u5230\u4fdd\u5b58\u811a\u672c\u7684\u76ee\u5f55\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">cd C:\\Users\\YourUsername\\Desktop<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884c\u811a\u672c\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u770b\u5230\u8f93\u51fa<code>Hello, Python 2.7!<\/code>\uff0c\u5219\u8bf4\u660e\u4f60\u7684Python\u811a\u672c\u8fd0\u884c\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u5728Mac\u548cLinux\u4e0a\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li>\u6253\u5f00Terminal\u3002<\/li>\n<li>\u5bfc\u822a\u5230\u4fdd\u5b58\u811a\u672c\u7684\u76ee\u5f55\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">cd ~\/Desktop<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884c\u811a\u672c\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u770b\u5230\u8f93\u51fa<code>Hello, Python 2.7!<\/code>\uff0c\u5219\u8bf4\u660e\u4f60\u7684Python\u811a\u672c\u8fd0\u884c\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6cd5<\/h2>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python 2.7\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>Python\u7248\u672c\u51b2\u7a81<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u4e2d\u540c\u65f6\u5b89\u88c5\u4e86Python 2.x\u548cPython 3.x\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7248\u672c\u51b2\u7a81\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u7248\u672c\u53f7\u6765\u8fd0\u884c\u7279\u5b9a\u7248\u672c\u7684Python\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">python2 hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u73af\u5883\u53d8\u91cf\u672a\u8bbe\u7f6e\u6b63\u786e<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python<\/code>\u547d\u4ee4\u65f6\u63d0\u793a\u627e\u4e0d\u5230\u547d\u4ee4\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u73af\u5883\u53d8\u91cf\u672a\u8bbe\u7f6e\u6b63\u786e\u3002\u8bf7\u53c2\u8003\u4e0a\u9762\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u90e8\u5206\uff0c\u786e\u4fddPython\u7684\u5b89\u88c5\u8def\u5f84\u5df2\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u811a\u672c\u6587\u4ef6\u540d\u51b2\u7a81<\/h3>\n<\/p>\n<p><p>\u786e\u4fdd\u4f60\u7684Python\u811a\u672c\u6587\u4ef6\u540d\u4e0d\u4e0ePython\u6807\u51c6\u5e93\u4e2d\u7684\u6a21\u5757\u540d\u51b2\u7a81\u3002\u4f8b\u5982\uff0c\u4e0d\u8981\u5c06\u4f60\u7684\u811a\u672c\u547d\u540d\u4e3a<code>time.py<\/code>\u6216<code>os.py<\/code>\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5bfc\u5165\u6a21\u5757\u65f6\u53d1\u751f\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h3>\u6743\u9650\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728Linux\u548cMac OS\u4e2d\uff0c\u5982\u679c\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528<code>chmod<\/code>\u547d\u4ee4\u4e3a\u811a\u672c\u6dfb\u52a0\u6267\u884c\u6743\u9650\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">chmod +x hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">.\/hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u516d\u3001Python 2.7\u7684\u57fa\u672c\u8bed\u6cd5<\/h2>\n<\/p>\n<p><p>\u4e86\u89e3\u548c\u638c\u63e1Python 2.7\u7684\u57fa\u672c\u8bed\u6cd5\u662f\u7f16\u5199Python\u7a0b\u5e8f\u7684\u57fa\u7840\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9bPython 2.7\u7684\u57fa\u672c\u8bed\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u6ce8\u91ca<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u7684\u6ce8\u91ca\u4f7f\u7528<code>#<\/code>\u7b26\u53f7\u5f00\u5934\uff0c\u5355\u884c\u6ce8\u91ca\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8fd9\u662f\u4e00\u4e2a\u5355\u884c\u6ce8\u91ca<\/p>\n<p>print(&quot;Hello, Python 2.7!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u591a\u884c\u6ce8\u91ca\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">&quot;&quot;&quot;<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u591a\u884c\u6ce8\u91ca<\/p>\n<p>\u53ef\u4ee5\u8de8\u8d8a\u591a\u884c<\/p>\n<p>&quot;&quot;&quot;<\/p>\n<p>print(&quot;Hello, Python 2.7!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b<\/h3>\n<\/p>\n<p><p>Python\u662f\u52a8\u6001\u7c7b\u578b\u8bed\u8a00\uff0c\u4e0d\u9700\u8981\u663e\u5f0f\u58f0\u660e\u53d8\u91cf\u7c7b\u578b\u3002\u5e38\u89c1\u7684\u6570\u636e\u7c7b\u578b\u5305\u62ec\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5217\u8868\u3001\u5143\u7ec4\u548c\u5b57\u5178\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6574\u6570<\/p>\n<p>x = 5<\/p>\n<h2><strong>\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>y = 3.14<\/p>\n<h2><strong>\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>name = &quot;Python&quot;<\/p>\n<h2><strong>\u5217\u8868<\/strong><\/h2>\n<p>fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<\/p>\n<h2><strong>\u5143\u7ec4<\/strong><\/h2>\n<p>coordinates = (10.0, 20.0)<\/p>\n<h2><strong>\u5b57\u5178<\/strong><\/h2>\n<p>person = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6761\u4ef6\u8bed\u53e5<\/h3>\n<\/p>\n<p><p>\u6761\u4ef6\u8bed\u53e5\u7528\u4e8e\u6839\u636e\u6761\u4ef6\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801\u5757\u3002Python\u7684\u6761\u4ef6\u8bed\u53e5\u4f7f\u7528<code>if<\/code>\u3001<code>elif<\/code>\u548c<code>else<\/code>\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 10<\/p>\n<p>if x &gt; 0:<\/p>\n<p>    print(&quot;x\u662f\u6b63\u6570&quot;)<\/p>\n<p>elif x == 0:<\/p>\n<p>    print(&quot;x\u662f\u96f6&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;x\u662f\u8d1f\u6570&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5faa\u73af<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u7684\u5faa\u73af\u5305\u62ec<code>for<\/code>\u5faa\u73af\u548c<code>while<\/code>\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># for\u5faa\u73af<\/p>\n<p>for i in range(5):<\/p>\n<p>    print(i)<\/p>\n<h2><strong>while\u5faa\u73af<\/strong><\/h2>\n<p>count = 0<\/p>\n<p>while count &lt; 5:<\/p>\n<p>    print(count)<\/p>\n<p>    count += 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u662f\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u5757\uff0c\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    print(&quot;Hello, &quot; + name + &quot;!&quot;)<\/p>\n<p>greet(&quot;Python 2.7&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u7c7b\u548c\u5bf9\u8c61<\/h3>\n<\/p>\n<p><p>Python\u662f\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u652f\u6301\u7c7b\u548c\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Dog:<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        self.name = name<\/p>\n<p>        self.age = age<\/p>\n<p>    def bark(self):<\/p>\n<p>        print(&quot;Woof!&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5bf9\u8c61<\/strong><\/h2>\n<p>my_dog = Dog(&quot;Buddy&quot;, 3)<\/p>\n<p>print(my_dog.name)<\/p>\n<p>my_dog.bark()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e03\u3001\u5e38\u7528Python\u5e93<\/h2>\n<\/p>\n<p><p>Python\u6709\u4e30\u5bcc\u7684\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684Python\u5e93\u3002<\/p>\n<\/p>\n<p><h3>\u6807\u51c6\u5e93<\/h3>\n<\/p>\n<p><h4>os\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u7528\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u76f8\u5173\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<\/strong><\/h2>\n<p>cwd = os.getcwd()<\/p>\n<p>print(&quot;\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55:&quot;, cwd)<\/p>\n<h2><strong>\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6<\/strong><\/h2>\n<p>files = os.listdir(&quot;.&quot;)<\/p>\n<p>print(&quot;\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6:&quot;, files)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>sys\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u7528\u4e8e\u4e0ePython\u89e3\u91ca\u5668\u4ea4\u4e92\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<h2><strong>\u83b7\u53d6\u547d\u4ee4\u884c\u53c2\u6570<\/strong><\/h2>\n<p>args = sys.argv<\/p>\n<p>print(&quot;\u547d\u4ee4\u884c\u53c2\u6570:&quot;, args)<\/p>\n<h2><strong>\u9000\u51fa\u7a0b\u5e8f<\/strong><\/h2>\n<p>sys.exit(0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>datetime\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u7528\u4e8e\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4<\/strong><\/h2>\n<p>now = datetime.datetime.now()<\/p>\n<p>print(&quot;\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4:&quot;, now)<\/p>\n<h2><strong>\u683c\u5f0f\u5316\u65e5\u671f\u548c\u65f6\u95f4<\/strong><\/h2>\n<p>formatted_date = now.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)<\/p>\n<p>print(&quot;\u683c\u5f0f\u5316\u65e5\u671f\u548c\u65f6\u95f4:&quot;, formatted_date)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><h4>NumPy<\/h4>\n<\/p>\n<p><p>\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u7ec4\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<\/strong><\/h2>\n<p>arr = np.array([1, 2, 3, 4, 5])<\/p>\n<p>print(&quot;\u6570\u7ec4:&quot;, arr)<\/p>\n<h2><strong>\u6570\u7ec4\u7684\u57fa\u672c\u64cd\u4f5c<\/strong><\/h2>\n<p>print(&quot;\u6570\u7ec4\u7684\u5f62\u72b6:&quot;, arr.shape)<\/p>\n<p>print(&quot;\u6570\u7ec4\u7684\u5747\u503c:&quot;, np.mean(arr))<\/p>\n<p>print(&quot;\u6570\u7ec4\u7684\u6807\u51c6\u5dee:&quot;, np.std(arr))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>Pandas<\/h4>\n<\/p>\n<p><p>\u7528\u4e8e\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>data = {&quot;name&quot;: [&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;],<\/p>\n<p>        &quot;age&quot;: [25, 30, 35]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>print(&quot;DataFrame:\\n&quot;, df)<\/p>\n<h2><strong>\u57fa\u672c\u64cd\u4f5c<\/strong><\/h2>\n<p>print(&quot;\u5e74\u9f84\u7684\u5747\u503c:&quot;, df[&quot;age&quot;].mean())<\/p>\n<p>print(&quot;\u5e74\u9f84\u7684\u6807\u51c6\u5dee:&quot;, df[&quot;age&quot;].std())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>Matplotlib<\/h4>\n<\/p>\n<p><p>\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [1, 4, 9, 16, 25]<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u5f62<\/strong><\/h2>\n<p>plt.plot(x, y)<\/p>\n<p>plt.xlabel(&quot;X\u8f74&quot;)<\/p>\n<p>plt.ylabel(&quot;Y\u8f74&quot;)<\/p>\n<p>plt.title(&quot;\u7b80\u5355\u6298\u7ebf\u56fe&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u516b\u3001Python 2.7\u4e0ePython 3.x\u7684\u533a\u522b<\/h2>\n<\/p>\n<p><p>Python 2.7\u548cPython 3.x\u6709\u4e00\u4e9b\u91cd\u8981\u7684\u533a\u522b\uff0c\u8fd9\u4e9b\u533a\u522b\u53ef\u80fd\u4f1a\u5f71\u54cd\u4f60\u7684\u4ee3\u7801\u7f16\u5199\u548c\u8fc1\u79fb\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4e3b\u8981\u533a\u522b\u3002<\/p>\n<\/p>\n<p><h3>\u6253\u5370\u8bed\u53e5<\/h3>\n<\/p>\n<p><p>\u5728Python 2.7\u4e2d\uff0c<code>print<\/code>\u662f\u4e00\u4e2a\u8bed\u53e5\uff0c\u4e0d\u9700\u8981\u62ec\u53f7\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print &quot;Hello, Python 2.7!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python 3.x\u4e2d\uff0c<code>print<\/code>\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u9700\u8981\u62ec\u53f7\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, Python 3.x!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u9664\u6cd5\u8fd0\u7b97<\/h3>\n<\/p>\n<p><p>\u5728Python 2.7\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u9ed8\u8ba4\u662f\u5411\u4e0b\u53d6\u6574\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(5 \/ 2)  # \u8f93\u51fa2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python 3.x\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u9ed8\u8ba4\u662f\u6d6e\u70b9\u9664\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(5 \/ 2)  # \u8f93\u51fa2.5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>Unicode\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u5728Python 2.7\u4e2d\uff0c\u5b57\u7b26\u4e32\u9ed8\u8ba4\u662fASCII\u7f16\u7801\uff0c\u9700\u8981\u4f7f\u7528<code>u<\/code>\u524d\u7f00\u6765\u8868\u793aUnicode\u5b57\u7b26\u4e32\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">s = u&quot;Hello, Unicode!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python 3.x\u4e2d\uff0c\u5b57\u7b26\u4e32\u9ed8\u8ba4\u662fUnicode\u7f16\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">s = &quot;Hello, Unicode!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>input\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5728Python 2.7\u4e2d\uff0c<code>input<\/code>\u51fd\u6570\u8bfb\u53d6\u8f93\u5165\u5e76\u6267\u884c\u4e3aPython\u4ee3\u7801\uff0c<code>raw_input<\/code>\u51fd\u6570\u8bfb\u53d6\u8f93\u5165\u4f5c\u4e3a\u5b57\u7b26\u4e32\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = input(&quot;Enter a number: &quot;)  # \u6267\u884c\u4e3aPython\u4ee3\u7801<\/p>\n<p>y = raw_input(&quot;Enter a string: &quot;)  # \u8bfb\u53d6\u4e3a\u5b57\u7b26\u4e32<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python 3.x\u4e2d\uff0c<code>input<\/code>\u51fd\u6570\u8bfb\u53d6\u8f93\u5165\u4f5c\u4e3a\u5b57\u7b26\u4e32\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = input(&quot;Enter a number: &quot;)  # \u8bfb\u53d6\u4e3a\u5b57\u7b26\u4e32<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e5d\u3001Python 2.7\u7684\u7ed3\u675f\u652f\u6301\u4e0e\u8fc1\u79fb\u5230Python 3.x<\/h2>\n<\/p>\n<p><p>Python 2.7\u7684\u5b98\u65b9\u652f\u6301\u5df2\u7ecf\u4e8e2020\u5e741\u67081\u65e5\u7ed3\u675f\uff0c\u8fd9\u610f\u5473\u7740\u4e0d\u518d\u6709\u5b98\u65b9\u7684\u5b89\u5168\u66f4\u65b0\u548c\u4fee\u590d\u3002\u56e0\u6b64\uff0c\u5efa\u8bae\u5c06\u4ee3\u7801\u8fc1\u79fb\u5230Python 3.x\u3002<\/p>\n<\/p>\n<p><h3>\u8fc1\u79fb\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>2to3<\/code>\u5de5\u5177\u6765\u81ea\u52a8\u5c06Python 2\u4ee3\u7801\u8f6c\u6362\u4e3aPython 3\u4ee3\u7801\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">2to3 -w your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u517c\u5bb9\u6027\u5e93<\/h3>\n<\/p>\n<p><p>\u4e00\u4e9b\u5e93\uff08\u5982<code>six<\/code>\uff09\u63d0\u4f9b\u4e86\u5728Python 2\u548cPython 3\u4e4b\u95f4\u7f16\u5199\u517c\u5bb9\u4ee3\u7801\u7684\u5de5\u5177\u3002\u4f7f\u7528\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u5e2e\u52a9\u4f60\u9010\u6b65\u8fc1\u79fb\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u9010\u6b65\u8fc1\u79fb<\/h3>\n<\/p>\n<p><p>\u9010\u6b65\u8fc1\u79fb\u53ef\u4ee5\u964d\u4f4e\u8fc1\u79fb\u8fc7\u7a0b\u4e2d\u7684\u98ce\u9669\u3002\u4f60\u53ef\u4ee5\u5148\u5c06\u4e00\u90e8\u5206\u4ee3\u7801\u8fc1\u79fb\u5230Python 3\uff0c\u7136\u540e\u9010\u6b65\u8fc1\u79fb\u5176\u4ed6\u90e8\u5206\u3002<\/p>\n<\/p>\n<p><p>\u603b\u4e4b\uff0c\u5c3d\u7ba1Python 2.7\u5df2\u7ecf\u7ed3\u675f\u652f\u6301\uff0c\u4ecd\u7136\u6709\u4e00\u4e9b\u9879\u76ee\u5728\u4f7f\u7528\u5b83\u3002\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u4f60\u53ef\u4ee5\u4e86\u89e3\u5982\u4f55\u5b89\u88c5\u548c\u8fd0\u884cPython 2.7\uff0c\u7f16\u5199\u548c\u8fd0\u884cPython\u811a\u672c\uff0c\u89e3\u51b3\u5e38\u89c1\u95ee\u9898\uff0c\u5e76\u4e86\u89e3Python 2.7\u7684\u57fa\u672c\u8bed\u6cd5\u548c\u5e38\u7528\u5e93\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5b89\u88c5Python 2.7\uff1f<\/strong><br \/>\u8981\u8fd0\u884cPython 2.7\uff0c\u9996\u5148\u9700\u8981\u5728\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff0c\u627e\u5230\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684Python 2.7\u7248\u672c\u8fdb\u884c\u4e0b\u8f7d\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u786e\u4fdd\u9009\u62e9\u5c06Python\u6dfb\u52a0\u5230\u7cfb\u7edf\u8def\u5f84\u7684\u9009\u9879\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5982\u4f55\u8fd0\u884cPython 2.7\uff1f<\/strong><br \/>\u5728Windows\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\u8fd0\u884cPython 2.7\uff0c\u8f93\u5165\u201cpython\u201d\u547d\u4ee4\u5373\u53ef\u542f\u52a8\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3002\u5728macOS\u548cLinux\u4e0a\uff0c\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\u201cpython\u201d\u540c\u6837\u53ef\u4ee5\u542f\u52a8\u3002\u5982\u679c\u5728\u7cfb\u7edf\u4e2d\u540c\u65f6\u5b89\u88c5\u4e86Python 2\u548cPython 3\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u201cpython2\u201d\u547d\u4ee4\u6765\u786e\u4fdd\u8c03\u7528\u7684\u662fPython 2.7\u7248\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python 2.7\u4e2d\u8fd0\u884c\u811a\u672c\u6587\u4ef6\uff1f<\/strong><br \/>\u8981\u8fd0\u884c\u4e00\u4e2aPython 2.7\u811a\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u4f7f\u7528\u201cpython script_name.py\u201d\u547d\u4ee4\uff0c\u5176\u4e2d\u201cscript_name.py\u201d\u662f\u4f60\u7684Python\u811a\u672c\u6587\u4ef6\u540d\u3002\u5982\u679c\u4f60\u5728\u6587\u4ef6\u540d\u4e2d\u4f7f\u7528\u4e86\u7a7a\u683c\uff0c\u8bb0\u5f97\u7528\u5f15\u53f7\u5c06\u5176\u62ec\u8d77\u6765\u3002<\/p>\n<p><strong>Python 2.7\u4e0ePython 3\u7684\u4e3b\u8981\u533a\u522b\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>Python 2.7\u4e0ePython 3\u4e4b\u95f4\u6709\u8bb8\u591a\u91cd\u8981\u533a\u522b\uff0c\u5305\u62ec\u6253\u5370\u8bed\u53e5\u7684\u8bed\u6cd5\u3001\u5b57\u7b26\u4e32\u5904\u7406\u65b9\u5f0f\u4ee5\u53ca\u67d0\u4e9b\u5e93\u7684\u529f\u80fd\u3002\u4e86\u89e3\u8fd9\u4e9b\u533a\u522b\u5bf9\u4e8e\u4ecePython 2.7\u8fc1\u79fb\u5230Python 3\u975e\u5e38\u91cd\u8981\u3002\u5c3d\u7ba1Python 2.7\u4ecd\u7136\u53ef\u4ee5\u4f7f\u7528\uff0c\u4f46\u5efa\u8bae\u65b0\u9879\u76ee\u4f7f\u7528Python 3\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u652f\u6301\u548c\u66f4\u65b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u8fd0\u884cPython 2.7\u7a0b\u5e8f\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Python 2.7\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u7f16\u5199Python\u811a\u672c\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1148997,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1148990"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1148990"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1148990\/revisions"}],"predecessor-version":[{"id":1149001,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1148990\/revisions\/1149001"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1148997"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1148990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1148990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1148990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}