python编程风格

语法要求
1:缩紧统一

>>> name = 'Alex'
>>> if name == 'alex':
...  print'hello',name
...
>>> if name == 'Alex':
...  print'hello',name
...
hello Alex

2:变量
(1)标识符的第一个字符必须是字母表中的字母(大写或小写)或者一个下划线(‘-’)
(2)标识符名称的其他部分可以由字母(大写或小写)、下划线(‘-’)或数字(0-9)组成。
(3)标识符名称是对大小写敏感的。例如,myname和myName不是一个标识符。注意前者中的小写n和后者 中的大写N。
(4)有效标识符名称的例子有i、__my_name、name_23和alb2_c3。
(5)无效标识符名称的例子有2things、this is space out和my-name。

>>> name = alex
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'alex' is not defined
>>>

alex不加引号’‘,相当于一个变量 ,程序会寻找 alex,然后报错name ‘alex’ is not defined

>>> alex = 'Alex Li'
>>> name = alex
>>> name
'Alex Li'
>>>

3:双引号及三引号用法

>>> a = "Hello,everybody,I'm Alex"
>>> a
"Hello,everybody,I'm Alex"
>>> a ='''Hello,everybody,Im Alex\n
... this is the second line,
... ojbk
... funcation earth
...
...
...
... '''
>>> a
'Hello,everybody,Im Alex\n\nthis is the second line,\nojbk\nfuncation earth\n\n\n\n'
>>>
>>> print a
Hello,everybody,Im Alex

this is the second line,
ojbk
funcation earth




>>>

4:查看模块详情

>>> help('sys')
Help on built-in module sys:

NAME
    sys

FILE
    (built-in)

MODULE DOCS
    http://docs.python.org/library/sys

DESCRIPTION
    This module provides access to some objects used or maintained by the
    interpreter and to functions that interact strongly with the interpreter.

    Dynamic objects:

    argv -- command line arguments; argv[0] is the script pathname if known
    path -- module search path; path[0] is the script directory, else ''
    modules -- dictionary of loaded modules

    displayhook -- called to show results in an interactive session
    excepthook -- called to handle any uncaught exception other than SystemExit
      To customize printing in an interactive session or to install a custom
      top-level exception handler, assign other functions to replace these.

    exitfunc -- if sys.exitfunc exists, this routine is called when Python exits
      Assigning to sys.exitfunc is deprecated; use the atexit module instead.

-- More  --

help完按q退出

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值