当前位置: 首页 > 工具软件 > Diesel-Python > 使用案例 >

Python解释器及IDLE的使用

东方俊力
2023-12-01
  1. Python解释器

想必大家都已经了解到Python是一种解释型语言,当我们装载了Python解释器之后,解释器会读取我们编写的程序并执行,我们会采用两种形式去使用解释器,他们分别是交互模式和文件模式。

  1. 交互模式

交互模式指的是我们在终端进入Python或者在IDLE中输入一行代码执行一次的模式,在后面的学习中,部分例题会采用交互模式。

以我们刚装载好的IDLE为例来介绍一下交互模式,首先我们找到我们的Python解释器,在当前页面可以直接进行交互。

201.png

注:以交互模式运行时通常被称为Python shell

我们可以看到‘>>>’这个符号,我们可以在他后面进行输入指令,首先我们来输入一条简单的指令看一下效果。

202.png

第一行为我们输入的信息,回车(enter)之后会看到第二行的信息,也就是解释器打印出的内容。(我们在一次交互模式下定义过的变量等都是可以重复使用的)

然后‘>>>’再次出现等待我们的第二次指令的发送。

下面再展示几个实例,此时你也可以打开你的解释器进行练习。

203.png

  在交互模式下如果出现错误代码系统会立刻报错。

204.png

  交互模式在我们学习新内容的时候可以得到及时的调试并得到反馈。



  2) 文件模式

  尽管交互模式在调试的时候使用着很方便,但却不利于保存,它只是简单的执行并显示在屏幕上,我们在需要编写之后并保存下来就要采用文件模式。

  我们可以创建一个文本文件并以.py结尾然后使用IDLE打开,或者在IDLE中直接点击File->New File进入一个文件,然后可以进行代码的编写。

  先编写一段入门代码:

205.png

  通过F5或者在Run中run Module执行文件。

  运行结果如下:

206.png

 

  3) 文件模式下进行交互

  文件模式下是先编写程序然后运行到shell页面

207.png

  然后我们运行它来进行交互

208.png208.png

  在交互的过程中,如果我们的主程序,也就是test.py是没有错误的,就可

  以在交互页面一直进行操作,哪怕是语法错误也仍在当前文件下。但是如果我们主       程序(test.py)出 现了语法错误,那么出现错误的语句下面的语句都不会被执行。

  我们来看个例子:

  代码如下:

209.png

  我们来研究分析一下当中间有一步为错误之后,后续语句是否会被处理。

210.png
  1. 总结

通过这些例子想必大家可以认识到交互模式、文件模式、以及文件模式下使用Python shell进行交互,在程序出错的时候是处于一个什么样的状态,在学习过程中,推荐大家采用第二种方式去进行学习开发。

下一节我们来介绍一款Python学习过程中最常用到的开发工具——Pycharm。
https://wenku.baidu.com/view/3ecc1696bc23482fb4daa58da0116c175f0e1eb0.html
https://wenku.baidu.com/view/ff3e8cbff042336c1eb91a37f111f18583d00cb2.html
https://wenku.baidu.com/view/e82390eba7e9856a561252d380eb6294dd8822b8.html
https://wenku.baidu.com/view/7f039e22fac75fbfc77da26925c52cc58bd690bd.html
https://wenku.baidu.com/view/7d80c7e5bf64783e0912a21614791711cc7979bf.html
https://wenku.baidu.com/view/b551c5ba8c9951e79b89680203d8ce2f006665be.html
https://wenku.baidu.com/view/23e1590fd7bbfd0a79563c1ec5da50e2524dd1a5.html
https://wenku.baidu.com/view/70138cf9ecfdc8d376eeaeaad1f34693dbef1052.html
https://wenku.baidu.com/view/f01ae8acdfccda38376baf1ffc4ffe473268fd57.html
https://wenku.baidu.com/view/4c5191de50d380eb6294dd88d0d233d4b04e3f59.html
https://wenku.baidu.com/view/791d6d269b8fcc22bcd126fff705cc1754275f5a.html
https://wenku.baidu.com/view/79686d269b8fcc22bcd126fff705cc1754275f47.html
https://wenku.baidu.com/view/5a916241a2116c175f0e7cd184254b35effd1a49.html
https://wenku.baidu.com/view/b04660a25afafab069dc5022aaea998fcd224075.html
https://wenku.baidu.com/view/68557dd6aa114431b90d6c85ec3a87c241288a77.html
https://wenku.baidu.com/view/612cb1b358cfa1c7aa00b52acfc789eb162d9e7e.html
https://wenku.baidu.com/view/f63a478129160b4e767f5acfa1c7aa00b42a9d63.html
https://wenku.baidu.com/view/f77fd76af724ccbff121dd36a32d7375a517c665.html
https://wenku.baidu.com/view/1672ac157d192279168884868762caaedc33ba67.html
https://wenku.baidu.com/view/e827ecda094e767f5acfa1c7aa00b52acec79c66.html
https://wenku.baidu.com/view/69d436eddf36a32d7375a417866fb84ae55cc369.html
https://wenku.baidu.com/view/357170fa094c2e3f5727a5e9856a561253d3216a.html
https://wenku.baidu.com/view/ae07c6d0a100a6c30c22590102020740bf1ecd6d.html
https://wenku.baidu.com/view/6c71c414cc2f0066f5335a8102d276a20129606e.html
https://wenku.baidu.com/view/24a5b8d52079168884868762caaedd3382c4b518.html
https://wenku.baidu.com/view/bc1468d3fe4ffe4733687e21af45b307e971f91d.html
https://wenku.baidu.com/view/8ed14ce94935eefdc8d376eeaeaad1f34693119c.html
https://wenku.baidu.com/view/95b5a020122de2bd960590c69ec3d5bbfc0ada1c.html
https://wenku.baidu.com/view/0bb584fe3b68011ca300a6c30c2259010302f300.html
https://wenku.baidu.com/view/7ab164e17175a417866fb84ae45c3b3566ecdd05.html
https://wenku.baidu.com/view/2f97e5b5148884868762caaedd3383c4ba4cb40a.html
https://wenku.baidu.com/view/3e491696bc23482fb4daa58da0116c175e0e1e0f.html
https://wenku.baidu.com/view/4a1f67dd6e175f0e7cd184254b35eefdc9d3150e.html
https://wenku.baidu.com/view/fab02df65a0216fc700abb68a98271fe910eafaf.html
https://wenku.baidu.com/view/725ede4486868762caaedd3383c4bb4cf7ecb7a5.html
https://wenku.baidu.com/view/b25defe44973f242336c1eb91a37f111f1850dbc.html
https://wenku.baidu.com/view/1506a3157d192279168884868762caaedd33babb.html
https://wenku.baidu.com/view/8ed14ce94935eefdc8d376eeaeaad1f34693119c.html
https://wenku.baidu.com/view/e21e25e30266f5335a8102d276a20029bc6463c2.html
https://wenku.baidu.com/view/b485ca33f505cc1755270722192e453611665b71.html
https://wenku.baidu.com/view/74d03c1e31d4b14e852458fb770bf78a64293a74.html
https://wenku.baidu.com/view/ff2a1e8e316c1eb91a37f111f18583d048640f77.html
https://wenku.baidu.com/view/597cebee1b2e453610661ed9ad51f01dc3815776.html
https://wenku.baidu.com/view/c854b4d769d97f192279168884868762cbaebb7b.html
https://wenku.baidu.com/view/6edc7ac992c69ec3d5bbfd0a79563c1ec4dad77f.html
https://wenku.baidu.com/view/d912625553e79b89680203d8ce2f0066f4336460.html
https://wenku.baidu.com/view/4ce53100d838376baf1ffc4ffe4733687f21fc03.html
https://wenku.baidu.com/view/f66d9bc7f58a6529647d27284b73f242326c3132.html
https://wenku.baidu.com/view/4485b522fac75fbfc77da26925c52cc58ad69037.html
https://wenku.baidu.com/view/3857a5a8996648d7c1c708a1284ac850ac020405.html
https://wenku.baidu.com/view/88d71b2048fe04a1b0717fd5360cba1aa9118c39.html
https://wenku.baidu.com/view/8c8477456a0203d8ce2f0066f5335a8103d26661.html
https://wenku.baidu.com/view/e3da4eda16791711cc7931b765ce0508773275c4.html
https://wenku.baidu.com/view/ab8ac2f35527a5e9856a561252d380eb639423c2.html
https://wenku.baidu.com/view/97f9dfa47c21af45b307e87101f69e314232fada.html
https://wenku.baidu.com/view/6f3e4cdd6e175f0e7cd184254b35eefdc9d315d1.html
https://wenku.baidu.com/view/c39dc7da094e767f5acfa1c7aa00b52acec79ccc.html
https://wenku.baidu.com/view/8c768dfbec06eff9aef8941ea76e58fafbb0452c.html
https://wenku.baidu.com/view/f5834925876a561252d380eb6294dd88d1d23d20.html
https://wenku.baidu.com/view/e38659e6cdc789eb172ded630b1c59eef9c79a02.html
https://wenku.baidu.com/view/f39fbe1f82eb6294dd88d0d233d4b14e84243e0b.html
https://wenku.baidu.com/view/ded404bd03f69e3143323968011ca300a7c3f6f1.html
https://wenku.baidu.com/view/043aaa5fd8ef5ef7ba0d4a7302768e9950e76ec7.html
https://wenku.baidu.com/view/54ac1df4356baf1ffc4ffe4733687e21ae45ff7c.html
https://wenku.baidu.com/view/9f3c20eebed126fff705cc1755270722182e592e.html
https://wenku.baidu.com/view/0ebb2ab1a06925c52cc58bd63186bceb19e8ed80.html
https://wenku.baidu.com/view/9a050f71940590c69ec3d5bbfd0a79563c1ed4a4.html
https://wenku.baidu.com/view/15280235acf8941ea76e58fafab069dc502247aa.html
https://wenku.baidu.com/view/7d853c3f4493daef5ef7ba0d4a7302768e996fad.html
https://wenku.baidu.com/view/f8461f8e316c1eb91a37f111f18583d048640f53.html
https://wenku.baidu.com/view/272b171a1b5f312b3169a45177232f60dccce755.html
https://wenku.baidu.com/view/a74ab2c27ed184254b35eefdc8d376eeafaa177b.html
https://wenku.baidu.com/view/281519a925d3240c844769eae009581b6ad9bd7c.html
https://wenku.baidu.com/view/6f98334cd6d8d15abe23482fb4daa58da1111c36.html
https://wenku.baidu.com/view/7599ea8cbc1e650e52ea551810a6f524cdbfcb39.html
https://wenku.baidu.com/view/aedd281652e2524de518964bcf84b9d529ea2cc1.html
https://wenku.baidu.com/view/15e60235acf8941ea76e58fafab069dc512247fc.html
https://wenku.baidu.com/view/449bdce73369a45177232f60ddccda38366be1c0.html

https://wenku.baidu.com/view/9ec1e4c3743231126edb6f1aff00bed5b9f3738a.html
https://wenku.baidu.com/view/6876301931d4b14e852458fb770bf78a64293a9b.html
https://wenku.baidu.com/view/6e7b8f25fac75fbfc77da26925c52cc58ad69062.html
https://wenku.baidu.com/view/3848b8106d1aff00bed5b9f3f90f76c660374c74.html
https://wenku.baidu.com/view/d73f1adc57270722192e453610661ed9ac515554.html
https://wenku.baidu.com/view/bdd99c3506a1b0717fd5360cba1aa81145318f50.html
https://wenku.baidu.com/view/47a790872c3f5727a5e9856a561252d381eb200c.html
https://wenku.baidu.com/view/9a76a7d5c7da50e2524de518964bcf84b9d52dbd.html
https://wenku.baidu.com/view/592b82e5473610661ed9ad51f01dc281e53a5685.html
https://wenku.baidu.com/view/a054cb2c9989680203d8ce2f0066f5335b8167c9.html
https://wenku.baidu.com/view/b9d22cd1aa114431b90d6c85ec3a87c241288afb.html
https://wenku.baidu.com/view/e32a45b1a06925c52cc58bd63186bceb18e8ed33.html
https://wenku.baidu.com/view/f8b7b3a5a65177232f60ddccda38376bae1fe038.html
https://wenku.baidu.com/view/ed6ae7e5667d27284b73f242336c1eb91b3733fd.html
https://wenku.baidu.com/view/ee3fe6e5667d27284b73f242336c1eb91b3733d0.html
https://wenku.baidu.com/view/f3385714d35abe23482fb4daa58da0116d171fd5.html
https://wenku.baidu.com/view/64312e9df21dc281e53a580216fc700aba6852e5.html
https://wenku.baidu.com/view/c1c23789b107e87101f69e3143323968001cf4e1.html
https://wenku.baidu.com/view/5a4cefc7f58a6529647d27284b73f242326c31d2.html
https://wenku.baidu.com/view/cac629ef4a2fb4daa58da0116c175f0e7dd11939.html
https://wenku.baidu.com/view/c93c29d2670e52ea551810a6f524ccbff021ca18.html
https://wenku.baidu.com/view/07b210aec8aedd3383c4bb4cf7ec4afe05a1b150.html
https://wenku.baidu.com/view/9fb74a44d2d233d4b14e852458fb770bf78a3ba1.html
https://wenku.baidu.com/view/ff59fe26e209581b6bd97f19227916888486b9ba.html
https://wenku.baidu.com/view/212d5b73f321dd36a32d7375a417866fb84ac087.html
https://wenku.baidu.com/view/b3de2819bbf3f90f76c66137ee06eff9aff849fb.html
https://wenku.baidu.com/view/3a8eadf965ec102de2bd960590c69ec3d4bbdbce.html
https://wenku.baidu.com/view/dd3e34cedc80d4d8d15abe23482fb4daa48d1d6b.html
https://wenku.baidu.com/view/67269bba8c9951e79b89680203d8ce2f01666570.html
https://wenku.baidu.com/view/3a8833ccb72acfc789eb172ded630b1c58ee9b4d.html
https://wenku.baidu.com/view/f4cefce5667d27284b73f242336c1eb91b373341.html
https://wenku.baidu.com/view/73a5fc020708763231126edb6f1aff00bed5708f.html
https://wenku.baidu.com/view/a8ecc122fac75fbfc77da26925c52cc58ad690ec.html
https://wenku.baidu.com/view/1e0da3faa12d7375a417866fb84ae45c3b35c2a8.html
https://wenku.baidu.com/view/b1273ce8cebff121dd36a32d7375a417876fc11f.html
https://wenku.baidu.com/view/ac95ddb51511cc7931b765ce050876323012741e.html
https://wenku.baidu.com/view/992a14ff81c4bb4cf7ec4afe04a1b0717ed5b300.html
https://wenku.baidu.com/view/749ac0dea01614791711cc7931b765ce04087a21.html
https://wenku.baidu.com/view/e64fdee1ef630b1c59eef8c75fbfc77da3699720.html
https://wenku.baidu.com/view/b2c0ee1f260c844769eae009581b6bd97e19bc23.html
https://wenku.baidu.com/view/b13b689d75232f60ddccda38376baf1ffd4fe34e.html
https://wenku.baidu.com/view/741c328b31687e21af45b307e87101f69f31fb71.html
https://wenku.baidu.com/view/1faac86db2717fd5360cba1aa8114431b80d8e70.html
https://wenku.baidu.com/view/ad793de128f90242a8956bec0975f46526d3a715.html
https://wenku.baidu.com/view/2bf24f1c4b649b6648d7c1c708a1284ac9500515.html
https://wenku.baidu.com/view/8c4b4f08b94cf7ec4afe04a1b0717fd5370cb214.html
https://wenku.baidu.com/view/485bc682747f5acfa1c7aa00b52acfc788eb9f4b.html
https://wenku.baidu.com/view/eb7f2cd4944bcf84b9d528ea81c758f5f61f29ae.html
https://wenku.baidu.com/view/b11badb125284b73f242336c1eb91a37f11132ae.html
https://wenku.baidu.com/view/4e2ca5db5d0e7cd184254b35eefdc8d377ee145b.html
https://wenku.baidu.com/view/b25aee1f260c844769eae009581b6bd97e19bc5d.html
https://wenku.baidu.com/view/206ebeef2d60ddccda38376baf1ffc4fff47e25d.html
https://wenku.baidu.com/view/c697b5d0f8d6195f312b3169a45177232e60e47f.html
https://wenku.baidu.com/view/8a7f0c1652e2524de518964bcf84b9d529ea2c7f.html
https://wenku.baidu.com/view/b607b1f20b12a21614791711cc7931b764ce7b7e.html
https://wenku.baidu.com/view/48ee69dd6e175f0e7cd184254b35eefdc9d31561.html
https://wenku.baidu.com/view/edcd3e2048fe04a1b0717fd5360cba1aa9118c1f.html
https://wenku.baidu.com/view/fc3492eb0522192e453610661ed9ad51f01d54be.html
https://wenku.baidu.com/view/7612cedea01614791711cc7931b765ce05087aa9.html
https://wenku.baidu.com/view/23253b83fc4733687e21af45b307e87100f6f856.html
https://wenku.baidu.com/view/79716d269b8fcc22bcd126fff705cc1754275f4e.html
https://wenku.baidu.com/view/2998a9176d1aff00bed5b9f3f90f76c660374c07.html
https://wenku.baidu.com/view/3ef1c5ee5b0102020740be1e650e52ea5518ceae.html
https://wenku.baidu.com/view/8b462173f321dd36a32d7375a417866fb94ac07e.html
https://wenku.baidu.com/view/626fa7bf00768e9951e79b89680203d8cf2f6a7e.html
https://wenku.baidu.com/view/633fd6f965ec102de2bd960590c69ec3d4bbdb61.html
https://wenku.baidu.com/view/e6a047ccb72acfc789eb172ded630b1c58ee9b65.html
https://wenku.baidu.com/view/84520331cad376eeaeaad1f34693daef5ff71365.html
https://wenku.baidu.com/view/b7fd86200b75f46527d3240c844769eae109a364.html
https://wenku.baidu.com/view/7dc23c3f4493daef5ef7ba0d4a7302768f996f64.html
https://wenku.baidu.com/view/2775171a1b5f312b3169a45177232f60dccce767.html
https://wenku.baidu.com/view/eacfd7751837f111f18583d049649b6649d70921.html
https://wenku.baidu.com/view/6a214aa25afafab069dc5022aaea998fcd22405d.html
https://wenku.baidu.com/view/522b42d3fe4ffe4733687e21af45b307e971f95c.html
https://wenku.baidu.com/view/05b3ab5fd8ef5ef7ba0d4a7302768e9950e76e5c.html
https://wenku.baidu.com/view/4d213000d838376baf1ffc4ffe4733687f21fc5f.html
https://wenku.baidu.com/view/10823877ff0a79563c1ec5da50e2524de418d05f.html
https://wenku.baidu.com/view/d837635553e79b89680203d8ce2f0066f433645f.html
https://wenku.baidu.com/view/2f60efce0540be1e650e52ea551810a6f424c87f.html
https://wenku.baidu.com/view/e10718ff588102d276a20029bd64783e08127d7f.html
https://wenku.baidu.com/view/5e45eaee1b2e453610661ed9ad51f01dc381577f.html
https://wenku.baidu.com/view/4f880dc55a1b6bd97f192279168884868662b87e.html
https://wenku.baidu.com/view/8a341ce128f90242a8956bec0975f46526d3a756.html
https://wenku.baidu.com/view/d9311a466729647d27284b73f242336c1fb93056.html
https://wenku.baidu.com/view/2727171a1b5f312b3169a45177232f60dccce759.html
https://wenku.baidu.com/view/1a3e7d0a9cc3d5bbfd0a79563c1ec5da51e2d659.html
https://wenku.baidu.com/view/d546cae44973f242336c1eb91a37f111f0850d59.html
https://wenku.baidu.com/view/7d913c3f4493daef5ef7ba0d4a7302768f996f59.html
https://wenku.baidu.com/view/df3805bd03f69e3143323968011ca300a7c3f65d.html
https://wenku.baidu.com/view/dce723e30266f5335a8102d276a20029bc64635d.html

 类似资料: