文章标题
来源:互联网 发布:广发百发大数据精选 编辑:程序博客网 时间:2024/06/05 05:40
简明
简明Python教程
关于Python编译器的选择
PyCharm、Eclipse with PyDev
前言、介绍、安装Python、最初的步骤、基本概念、运算符与表达式、控制流
函数
函数通过def关键字定义,该行以冒号结尾
def sayHello(): print 'Hello World!' # block belonging to the functionsayHello() # call the function
局部变量与全局变量
def fuc(): global x # 全局变量 print 'x is',x x=2 print 'Changed local x to',xx=50fuc()print 'Value of x is',x#输出的值为:50 , 2 ,2
默认参数值
只有在形参表末尾的那些参数可以有默认参数值,即你不能在声明函数形参的时候,先声明有默认值的形参而后声明没有默认值的形参。
这是因为赋给形参的值是根据位置而赋值的。例如,def func(a, b=5)是有效的,但是def func(a=5, b)是 无效 的。
关键参数
#!/usr/bin/python# Filename: func_key.pydef func(a, b=5, c=10): print 'a is', a, 'and b is', b, 'and c is', cfunc(3, 7)func(25, c=24)func(c=50, a=100)#3 7 10#25 5 24#100 5 50
DocStrings
#!/usr/bin/python# Filename: func_doc.pydef printMax(x, y): '''Prints the maximum of two numbers. The two values must be integers.''' x = int(x) # convert to integers, if possible y = int(y) if x > y: print x, 'is maximum' else: print y, 'is maximum'printMax(3, 5)print printMax.__doc__#注意!!!printMax.__doc__中,前后皆为两双下划线
模块
模块基本上就是一个包含了所有你定义的函数和变量的文件。为了在其他程序中重用模块,模块的文件名必须以.py为扩展名。
sys模块
#!/usr/bin/python# Filename: using_sys.pyimport sysprint 'The command line arguments are:'for i in sys.argv: print iprint '\n\nThe PYTHONPATH is', sys.path, '\n'
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- Android 开发工程师面试指南
- iOS查看崩溃信息
- Play的model层,数据库配置
- leetcode No60. Permutation Sequence
- 正则表达式
- 文章标题
- iOS折线图
- Java回调~mqtt回调处理中的问题
- 数据结构实验之栈七:出栈序列判定
- ORACLE实现字符串分割SPLIT
- 简单实用的Android ORM框架TigerDB
- 2016 Multi-University Training Contest 3 1011 Teacher Bo(模拟)
- Android应用分身功能介绍
- 【CDOJ 1341】卿学姐与城堡的墙