Python自学笔记2-语法
来源:互联网 发布:新手学淘宝开店 编辑:程序博客网 时间:2024/06/06 01:44
这里介绍Python的基本语法和编程风格。
Python的保留字(如下表,不能以这些名字给函数或变量命名)
andexecnotassertfinallyorbreakforpassclassfromprintcontinueglobalraisedefifreturndelimporttryelifinwhileelseiswithexceptlambdayield代码缩进:
Python的代码不用括号区分结构,而是用空格。创建一块代码,需要四个空格,通常也就是按一个tab键。
例如:
defbar(x):
ifx==0:
foo()
else:
foobar(x)
Python是动态语言,不需要在定义变量时,声明变量的类型。例如:
1
2
3
x=2
y="Hello World"
z=-3
可以利用type()方法查看变量类型:
printtype(x)
会输出 <class 'int'>,变量为整数型
Python对空格有严格要求,不能用tab键,像如下一样对齐代码:
x =2
sentence ="Hello World"
variable_z =-3
可以用一个空格隔开
2
3
x=2
sentence="Hello World"
variable_z=-3
2
3
x=2
sentence="Hello World"
variable_z=-3
1
2
3
# 这里是单行注释,不会执行
x=3
y=2
2
2
3
4
5
''' 这里是多
行注释 '''
x=3
y=2
2
3
x=2
sentence="Hello World"
variable_z=-3
2
3
4
5
''' This is a
multi-line Python
comment. '''
x=3
y=2
0 0
- Python自学笔记2-语法
- python自学笔记 2
- python自学笔记2
- java自学笔记2(基本语法)
- 【python3自学笔记2】—基本语法
- 自学笔记:Python(2) 列表
- Python自学笔记系列一——基础语法
- 自学Python之 基础语法
- 自学java语法笔记总结
- 简明python教程自学笔记(2)
- python自学笔记2之pylint
- python自学笔记(2)--数据类型
- python自学笔记1
- python自学笔记 3
- python自学笔记 4
- python自学笔记
- Python自学笔记
- python自学笔记 20151126
- json 使用总结
- 微信支付遇到的问题总结
- Link2SD工具使用(将软件移动到sd卡中,详细)
- POJ 2284-That Nice Euler Circuit(计算几何_欧拉定理求平面被分成的区域数)
- poj3114--Countries in War(强连通缩点+spfa)
- Python自学笔记2-语法
- Android项目创建和项目目录图解
- Mercurial 、tortoisehg、 hg serve、hg web的区别和介绍
- Android4.4 背光亮度最低设置
- tuple
- C++中的类型转换
- tomcat进程意外退出的问题分析
- 关于servlet监听器的笔记与案例
- Jsp四大作用域