Warning: Undefined array key "wenan" in /www/wwwroot/suitangyanyi.com/jianzhan/app/show.php on line 46

Warning: Trying to access array offset on value of type null in /www/wwwroot/suitangyanyi.com/jianzhan/app/show.php on line 46
30.从入门到精通:Python3 命名空间和作用域 命名空间 作用域 Python3 标准库概览 操作系统接口 文件通配符 命令行参数 错误输出重定向和程序终止 字符串正则匹配 访问 互联网 日期和-隋唐演义故事网-

{site_name}

{site_name}

🌜 搜索

30.从入门到精通:Python3 命名空间和作用域 命名空间 作用域 Python3 标准库概览 操作系统接口 文件通配符 命令行参数 错误输出重定向和程序终止 字符串正则匹配 访问 互联网 日期和

▥ 𝄐 0
python入门到精通教程完整版,python从入门到精通pdf免费下载,python从入门到精通pdf下载清华大学出版社,python从入门到精通怎么样<br><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px"><strong>在Python中&#xff0c;命名空间是指用于存储变量名称和其对应值的区域。每个命名空间都有一个唯一的名称&#xff0c;并且在不同的命名空间中可以使用相同的变量名称&#xff0c;而不会互相干扰。</strong></p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">Python中有以下几种命名空间&#xff1a;</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">内置命名空间&#xff08;built-in namespace&#xff09;&#xff1a;包含了Python解释器内置的函数和变量&#xff0c;例如print()函数和int类型。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">全局命名空间&#xff08;globalnamespace&#xff09;&#xff1a;在模块中定义的变量和函数属于全局命名空间。在模块中定义的变量和函数可以在模块中的任何位置访问。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">局部命名空间&#xff08;local namespace&#xff09;&#xff1a;在函数内部定义的变量和函数属于局部命名空间。在函数内部定义的变量和函数只能在函数内部访问。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px"><strong>当Python解释器遇到一个变量时&#xff0c;它会按照以下顺序查找命名空间&#xff1a;</strong></p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">1.首先查找局部命名空间&#xff0c;如果变量在局部命名空间中找到&#xff0c;则使用该变量。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">2.如果变量不在局部命名空间中&#xff0c;则查找全局命名空间。如果变量在全局命名空间中找到&#xff0c;则使用该变量。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">3.如果变量不在全局命名空间中&#xff0c;则查找内置命名空间。如果变量在内置命名空间中找到&#xff0c;则使用该变量。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">4.如果变量在任何一个命名空间中都没有找到&#xff0c;则会引发NameError异常。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">需要注意的是&#xff0c;当在函数内部访问一个变量时&#xff0c;Python解释器会首先查找局部命名空间&#xff0c;如果该变量在局部命名空间中不存在&#xff0c;则会查找全局命名空间。如果该变量在全局命名空间中也不存在&#xff0c;则会引发NameError异常。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px"><strong>Python3中有两种作用域&#xff0c;分别是全局作用域和局部作用域。</strong></p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px"><em>全局作用域是指在整个程序中都可以访问的变量&#xff0c;一般定义在程序的最外层。在函数内部可以通过global关键字来声明一个变量为全局变量。</em></p><ul style="list-style-type:disc;margin:0px;padding-left:23px;font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none"><li>局部作用域是指在函数内部定义的变量&#xff0c;只能在函数内部访问。当函数执行完毕后&#xff0c;局部变量的作用域也就结束了。在函数内部可以通过nonlocal关键字来声明一个变量为非局部变量&#xff0c;即在嵌套函数中访问外层函数的变量。</li></ul><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">在Python3中&#xff0c;变量的作用域遵循LEGB规则&#xff0c;即Local&#xff08;局部&#xff09;、Enclosing&#xff08;嵌套&#xff09;、Global&#xff08;全局&#xff09;、Built-in&#xff08;内置&#xff09;的顺序。当在函数内部访问一个变量时&#xff0c;Python3会按照这个顺序查找变量的值。例如&#xff0c;如果在函数内部访问一个变量&#xff0c;Python3会首先查找局部作用域中是否存在这个变量&#xff0c;如果不存在&#xff0c;则查找嵌套作用域中是否存在这个变量&#xff0c;如果还不存在&#xff0c;则查找全局作用域中是否存在这个变量&#xff0c;最后查找内置作用域中是否存在这个变量。如果在所有作用域中都找不到这个变量&#xff0c;Python3会抛出NameError异常。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px"><strong>Python标准库是Python语言的核心部分之一&#xff0c;它提供了许多有用的模块和函数&#xff0c;可以用于各种不同的任务。以下是Python标准库的一些常用模块和函数的概述&#xff1a;</strong></p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">os模块&#xff1a;提供了与操作系统交互的函数&#xff0c;例如文件操作、进程管理等。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">sys模块&#xff1a;提供了与Python解释器交互的函数&#xff0c;例如命令行参数、标准输入输出等。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">re模块&#xff1a;提供了正则表达式操作的函数。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">datetime模块&#xff1a;提供了日期和时间操作的函数。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">random模块&#xff1a;提供了生成随机数的函数。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">math模块&#xff1a;提供了数学函数&#xff0c;例如三角函数、指数函数等。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">json模块&#xff1a;提供了JSON编码和解码的函数。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">urllib模块&#xff1a;提供了HTTP请求的函数。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">sqlite3模块&#xff1a;提供了SQLite数据库的函数。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">csv模块&#xff1a;提供了CSV文件读写的函数。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">以上只是Python标准库中的一小部分&#xff0c;还有许多其他有用的模块和函数&#xff0c;可以根据需要选择使用。可以通过Python官方文档查看完整的标准库文档。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">操作系统接口是指操作系统提供给应用程序或用户的一组功能和服务&#xff0c;用于访问和管理计算机硬件和软件资源。操作系统接口可以分为以下几类&#xff1a;</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">文件系统接口&#xff1a;用于管理文件和目录&#xff0c;包括创建、删除、移动、复制、重命名等操作。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">进程管理接口&#xff1a;用于管理进程&#xff0c;包括创建、终止、调度、同步、通信等操作。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">内存管理接口&#xff1a;用于管理计算机内存&#xff0c;包括分配、释放、保护、共享等操作。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">设备管理接口&#xff1a;用于管理计算机硬件设备&#xff0c;包括初始化、读写、控制、中断处理等操作。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">网络管理接口&#xff1a;用于管理计算机网络&#xff0c;包括连接、断开、传输、协议处理等操作。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">不同的操作系统提供的接口可能有所不同&#xff0c;但是它们都提供了一定程度的标准化接口&#xff0c;以便应用程序能够在不同的操作系统上运行。例如&#xff0c;POSIX接口是一组标准化的操作系统接口&#xff0c;可以在Unix和类Unix操作系统上使用。而Windows操作系统提供的接口则是基于Win32</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">API和.NET Framework的。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px"><strong>文件通配符是一种用于匹配文件名的模式&#xff0c;通常用于在命令行中指定一组文件。在Unix和类Unix操作系统中&#xff0c;文件通配符通常使用shell扩展来实现。</strong></p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">以下是常用的文件通配符&#xff1a;</p><ul style="list-style-type:disc;margin:0px;padding-left:23px;font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none"><li>*&#xff1a;匹配任意字符&#xff0c;包括空字符。</li><li>?&#xff1a;匹配任意单个字符。</li><li>[…]&#xff1a;匹配括号内的任意一个字符。例如&#xff0c;[abc]可以匹配字符a、b或c。</li><li>[<sup>…]&#xff1a;匹配不在括号内的任意一个字符。例如&#xff0c;[</sup>abc]可以匹配除了字符a、b和c之外的任意字符。</li></ul><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">例如&#xff0c;如果要匹配所有以.txt结尾的文件&#xff0c;可以使用通配符*.txt。如果要匹配所有以数字开头的文件&#xff0c;可以使用通配符[0-9]。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">在Python中&#xff0c;可以使用glob模块来实现文件通配符匹配。例如&#xff0c;glob.glob(&#39;.txt’)可以匹配当前目录下所有以.txt结尾的文件。</p><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px"><strong>在计算机程序中&#xff0c;命令行参数是指在程序启动时&#xff0c;从命令行传递给程序的一组参数。这些参数可以用来控制程序的行为&#xff0c;或者传递程序需要的数据。</strong></p><ul style="list-style-type:disc;margin:0px;padding-left:23px;font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none"><li>在Python中&#xff0c;可以使用sys模块中的argv变量来获取命令行参数。argv变量是一个列表&#xff0c;其中第一个元素是程序本身的名称&#xff0c;后面的元素是传递给程序的命令行参数。.</li></ul><p style="font-size:14px;color:rgb( 38 , 38 , 38 );line-height:1.74;letter-spacing:0.05em;outline-style:none;margin:0px">例如&#xff0c;下面是一个简单的Python程序&#xff0c;可以接受两个命令行参数并将它们相加&#xff1a;</p><div><div style="border:1px solid rgb( 232 , 232 , 232 );max-width:750px;color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:rgb( 249 , 249 , 249 )"><div style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"><pre style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )">import sys </span></span><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )">if len(sys.argv) !&#61; 3: </span></span><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"> print(&#34;Usage: python program.py arg1 arg2&#34;) </span></span><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )">else: </span></span><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"><span style="color:rgb( 24 , 24 , 24 );margin:0px;padding:0px;background:none 0% 0% / auto repeat scroll padding-box border-box rgba( 0 , 0 , 0 , 0 )"> arg1 &#61; int(sys.argv[1]) </span></spa<br>..淘宝扫一扫在哪里打开,淘宝扫一扫在哪里打开,淘宝助力入口在哪里找, 一直致力于618淘宝理想生活狂欢季淘宝活动互助群2023怎么进,天猫618 购物狂欢节淘宝扫一扫在哪里打开,现有116个群,还在持续增长中,总人数超过上万人。