Python编程基础实验指南.pdf
一本关于python入门的书籍,介绍了一些关于python语言的使用和开发3实践练习: Python函数和高级特性593.1 Python数的相关运用593.2 Python常用的高级特性674实践练习: Python函数式编程和模块784.1高阶函数,.,,,784.2返回函数,8243帮名函数834.4装饰器844.5偏函数874.6使用模块894.7安装第三方模块,,,,,1035实践练习: Python的面向对象编程1055.1面向对象的基础编程1055.2面向对象的高级编程1196实践练习: Python应用开发1366.1错误、调试,1366.2 virtualeny,1436.3 Python IyO读写,1456.4进程和线程,,,,,,,,,,,,,1496.5正则表达式156III重庆翰海睿智大数据科技有限公司1实践练习: Python安装及基本运用11 Python下载与安装1.日前, Python有两个版本,一个是2x版,一个是3x版,这两个版本是不兼容的。由于3X版越来越普及,我们的教程将以最新的 Python3.6版本为基础。请确保你的电脑上安装的 Python版本是最新的3.6x下载官网下载地址:https://www.python.org/downloads/windows2 Fychon Releases tcr Wir x+>O 2 Python Snthvara Foundaton lIS] python.ore/dowriosds/windowsDocsCommunitye pythonarchDownloads DocumentationCom munitySuccess storEventsPython>》 Downloads》 WindowsPython Releases for WindowsLatest Python 2 Release Python 2713Latest Python 3 Release-Python 3.5a Pyran 6 1-3n//I Downbad Windows x85 web-based installerDownload Windows xB executable installerDown Dad Windows x8 embeddable io fileDownl]ad Windows x82-G4wcb-bascd installerDownlad Windows x83-G4 executable installerDownlad Windows xBj-64 embeddable rip file图1: Python官网下载页面2.首先,根据你的 Windows版本(64位还是32位)从 Python重庆翰海睿智大数据科技有限公司的官方网站下载 Python3.6对应的64位安装程序或32位安装程序(网速慢的同学请移步国內镜像),然后,运行下载的EXE安装包。pYthon 2.6.1(64-bit)SetupInstall Python 3.6.1(64 bit)Select Install Now to install Python with default settings, or chooseCusluniize lu enable ui disebe edlures中 nstall nowC: \Users\ Data\LccalPrograms\ Python\ Python36Includes IDLE, pip and documentationCreates shortcuts and fie associations->Customize installationChoose location and fcaturcspytheO∩M Install launcher for all users (recommended)WIndOWS区 Add python3 tc pathCancel图2: Python3.6.1安装特别要注意勾上 Add Python3.6 to PaTh,然后点“ Install now”即可完成安装。3.安装成功后,打开命令提示符窗口,敲入 py thon2重庆翰海睿智大数据科技有限公司C=C: WINDOWS\system32\cmd. exe- pythonc)2016 Microsoft Corporation。保留所有权Users强> pythonthon3.6.1(v3.6.1:69c0db5,Mar2⊥2017,18:41:36)IMSC V 1900 64 bit(AMD64)] on win32ype help,copyright, credits or license formore information图3: Python安装成功12执行 Python脚本文件1.在D盘创建一个 My Py thon.py文件, MyPython py中代码如下:#我的第一个 Python文件2 print("Hello World")a print('Hello Python)2.打开CMD命令窗口,切换到 My Python. py所在的目录,然后执行下面的命python MyPython py3.输出结果aHello WorldHello python重庆翰海睿智大数据科技有限公司13 Python入门基础1. Python与其他语言最大的区别就是, Python的代码块不使用大括号(})来控制类,凼数以及其他逻辑判断, python最具特色的就是用缩进来写模块。正确写法如下a if Trueprint("True")else:print("False错误写法如下:alif Trueprint(" true")else:aprint("False")2. Python语句中一般以新行作为为语句的结束符。但是我们可以使用斜杠(\)将一行的语句分为多行显示。1a=10b=20.33C=304 sum =aprint(sum)4重庆翰海睿智大数据科技有限公司语句中包含[],仆或()括号就不需要使用多行连接符days =['Monday','Tuesday',' WednesdayThursday 1Friday3. Python接收单引号’,双引号",三引号'""来表小字符串,引号的开始与结束必须的相同类型的。1 name ='Pvthonsent="这是一条语句"3 para=ll这是一个段落4|包含了多个语句"""s print(name + '\n'+ sent +'\n'+ para)4.使用 input()和 print()执行输入输出。print(请输入您的姓名')# Python输出使用 print()name= input()# Python输入使用 Input()aprint(name)#输出用户所输入的内容5.在 Python缩进相同的一组语句构成一个代码块,我们称之代码组。像if、 While、def和 class这样的复合语句,首行以关键字开始,以冒号〔:)结束,该行之后的一行或多行代码构成代码组。我们将首行及后面的代码组称为一个子句( clause)。1 num =22 if num ==1:print('当前num的值是为1)lif num ==2print(当前num的值是为2)重庆翰海睿智大数据科技有限公司elseprint(当前num的值是不是1,也不是2)6. Python命令行参数,很多程序可以执行一些操作来查看一些基本信, Python可以使用-h或者-heLp参数査看各参数帮助信息。a python输出结果:usage: python [option]..[-c cmd I-m mod I file 1-][→arg]...后面进行了省略。14 Python集成开发环境 PyCharm的安装1.首先去下载最新的 Py Charm,进行安装。可以直接在官下载。https://www.jetbrains.com/pycharm/-yoram①女Py charmWhat's New Features Docs Demar Buy DownEDITIONPy charmPy charmProfessionalCommunityEditioEditionIntelligent Pythoneditarand test runnerNavigation andRefactoring图4: Py Charm下载地址6
下载地址
用户评论