Python----语法基础
2016-11-18 12:56
447 查看
标识符
首字符是字母或下划线
其余可以是字母、下划线、数字
大小写敏感(PI和pi是不同的标识符)
Python does not allow punctuation characters such as @, $, and % within identifiers.
以单个下划线 _ 开头的标识符是私有的(private)
以两个下划线 __ 开头的标识符 表示其 是强类型私有
If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Lines and Indentation
python无括号,语句结构依赖每行前的空格数判断
Multi - Line Statements
Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character (\) to denote that the line should continue. For example:
Statements contained within the [], {}, or () brackets do not need to use the line continuation character. For example:
case1:以[]申明[b]即列表[/b]
[b]
[/b]
case2:以()声明即元组
case3:以{}声明[b]即映射[/b]
[b]
[/b]
Quotation in Python
三种类型:'' ,'' '',''' '''.
区别在于三引号可跨越多行
eg.
注意用三引号后,输出内容中带有 \n
Comments in Python
# 用来做注解
Using Blank Lines
函数之间或类之间用空行分隔,表示一段新的代码的开始。
类和函数入口之间也用一行空行分隔,以突出函数入口的开始。
简单的讲,就是分隔不同功能的代码块
Waiting for the User
Multiple Statements on a Single Line
用 ; 实现一行使用多条语句
关键字
不可作为标识符名
andas assert break class continue def del
elif else except exec finally for from global
if import in is lambda not or pass
print raise return try while with yield
首字符是字母或下划线
其余可以是字母、下划线、数字
大小写敏感(PI和pi是不同的标识符)
Python does not allow punctuation characters such as @, $, and % within identifiers.
命名惯例:
只有class(类)以大写字母形式开头以单个下划线 _ 开头的标识符是私有的(private)
以两个下划线 __ 开头的标识符 表示其 是强类型私有
If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Lines and Indentation
python无括号,语句结构依赖每行前的空格数判断
Multi - Line Statements
Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character (\) to denote that the line should continue. For example:
Statements contained within the [], {}, or () brackets do not need to use the line continuation character. For example:
case1:以[]申明[b]即列表[/b]
[b]
[/b]
case2:以()声明即元组
case3:以{}声明[b]即映射[/b]
[b]
[/b]
Quotation in Python
三种类型:'' ,'' '',''' '''.
区别在于三引号可跨越多行
eg.
注意用三引号后,输出内容中带有 \n
Comments in Python
# 用来做注解
Using Blank Lines
函数之间或类之间用空行分隔,表示一段新的代码的开始。
类和函数入口之间也用一行空行分隔,以突出函数入口的开始。
简单的讲,就是分隔不同功能的代码块
Waiting for the User
Multiple Statements on a Single Line
用 ; 实现一行使用多条语句
关键字
不可作为标识符名
andas assert break class continue def del
elif else except exec finally for from global
if import in is lambda not or pass
print raise return try while with yield
相关文章推荐
- Python连载系列之Python语法基础3:Python中的字符串和数据结构
- Python 基础语法(二)
- Python基础语法
- 【python】python语法基础
- Python基础语法学习(字符串)
- Python连载系列之Python语法基础1:开始使用Python
- python 基础教程之语法篇章——一小时入门python__对比python与C语言的语法异同
- Python 基础语法知识(二)
- Python 基础语法知识(一)
- Python语法基础——关于全局变量与局部变量
- Python 基础语法(三)
- python学习日记1--基础语法篇
- learning python of 基础语法
- Python 基础语法知识(三)
- Python2 基础语法(三)
- Python 基础语法(一)
- Python 基础语法知识
- Python2 基础语法(一)
- Python的基础语法
- Python语法基础——关于全局变量与局部变量