您的位置:首页 > 编程语言 > Python开发

Python----语法基础

2016-11-18 12:56 447 查看
标识符

首字符是字母或下划线

其余可以是字母、下划线、数

大小写敏感(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: