Python语言的一些基本常用语句
在学习玩蛇网python教程高级篇之前,大家接触过许多python语句,在本文中我们将Python一些基本的常用语句做了汇总,并简单介绍下这些python常用语句的用途和标准格式,放在一起方便大家参考回顾。
(1)、赋值:创建变量引用值
a,b,c='aa','bb','cc'
(2)、调用:执行函数
log.write('spam,name')
打印、输出:调用打印对象,print 语句
print ('abc')
(3)if、elif、else:选择条件语句,if语句、else与elif语句
if 'iplaypython' in text: print (text)
(4)for、else:序列迭代
for x in list: print x
(5)、while、else:一般循环语句
while a > b : print 'hello'
(6)、pass:占位符(空)
while True: pass
(7)、break:退出循环
while True: if exit: break
(8)、continue:跳过当前循环,循环继续
while True: if skip: continue
下面的语句是相对比较大的程序中会用到,有关函数、类、异常以及模块,同样只是简单介绍方法用途和格式。
(9)、def:定义函数和方法
def info(a,b,c=3,*d): print (a+b+c+d[1])
(10)、return:函数返回值
def info(a,b,c=3,*d): return a+b+c+d[1]
(11)、python global:命名空间、作用域
x = 'a' def function(): global x ; x = 'b'
(12)、import:访问、导入模块
import sys
(13)、from:属性访问
from sys import stdin
(14)、class:创建对象,类class定义方法
class Person: def setName(self,name): self.name = name def getName(self): return self.name def greet(self): print 'hello,%s' % self.nameclass Person: def setName(self,name): self.name = name def getName(self): return self.name def greet(self): print 'hello,%s' % self.names
(15)、try、except、finally:python 捕获异常
try: action() except: print ('action error')
(16)、raise:触发异常
raise Endsearch (location)
(17)、assert:python 断言、检查调试
assert a>b ,'a roo small'
以上是为有基础的同学们做的方法概要,对于python初学者,可以点击语句查看具体操作方法介绍。
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/jinjie/jj140.html
相关文章 Recommend
- • 2019年3月最新消息: Python 3.4.10 现已推出
- • [上海]招Python量化系统开发工程师
- • 优集品网络科技有限公司招Python中/高级工程师
- • 爱因互动科技发展有限公司招募Python开发攻城狮
- • mozio招聘Python/Django工程师
- • Kavout金融科技公司招Python研发工程师
- • Python数组逆向输出,编程练习题实例四十
- • Python数组插入排序,编程练习题实例三十九
- • Python矩阵for循环应用,编程练习题实例三十八
- • Python操作Redis数据库方面的问题
- • 请python高手帮我看看这段python代码中函数setter的
- • Python什么方法可以快速将两个队列变成字典
PYTHON基础入门必备教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
PYTHON进阶提高必备教程 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • Python列表添加 insert() 插入元素方法
- • Python列表删除 pop() 方法返回指定对象
- • Python else与elif语句语法讲解
- • Python IOError错误异常原因
- • Python列表排序 reverse、sort、sorted 操作方法
- • 使用 from import方法导入Python模块
- • Python break语句 跳出循环
- • Python return语句 函数返回值
- • Python import语句导入模块语法
- • python assert 断言详细用法格式
图文精华 RECOMMEND
-
Python列表添加 insert() 插入元素方
-
Python列表删除 pop() 方法返回指定
-
Python else与elif语句语法讲解
-
Python列表排序 reverse、sort、sorte
-
Python break语句 跳出循环
-
Python return语句 函数返回值
热点文章 HOT
- Python语言的一些基本常用语句
- Python 字典items返回列表,iteritems返回迭代
- Python函数的形参和实参详解
- Python is同一性运算符和==相等运算符区别
- Python for循环控制语句一般格式及方法
- Python 序列的概念及基本操作方法
- python assert 断言详细用法格式
- python if控制流语句 语法笔记
- Python 函数的关键字参数和位置参数
- Python条件语句的嵌套使用