语法要求
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退出