1、介绍
略
2、安装Python
略
3、最初的步骤
(1)获取帮助help()
- help()的使用帮助
1 >>> help("help") 2 3 Welcome to Python 2.7! This is the online help utility. 4 5 If this is your first time using Python, you should definitely check out 6 the tutorial on the Internet at http://docs.python.org/2.7/tutorial/. 7 8 Enter the name of any module, keyword, or topic to get help on writing 9 Python programs and using Python modules. To quit this help utility and 10 return to the interpreter, just type "quit". 11 12 To get a list of available modules, keywords, or topics, type "modules", 13 "keywords", or "topics". Each module also comes with a one-line summary 14 of what it does; to list the modules whose summaries contain a given word 15 such as "spam", type "modules spam". 16 17 >>> 18 >>>
- help()获取模块的帮助
1 >>> help("math") 2 Help on built-in module math: 3 4 NAME 5 math 6 7 FILE 8 (built-in) 9 10 DESCRIPTION 11 This module is always available. It provides access to the 12 mathematical functions defined by the C standard. 13 14 FUNCTIONS 15 acos(...) 16 acos(x) 17
- help()获取类的帮助
1 >>> help("str") 2 Help on class str in module __builtin__: 3 4 class str(basestring) 5 | str(object=‘‘) -> string 6 | 7 | Return a nice string representation of the object.
- help()获取方法的帮助
1 >>> help("str.split") 2 Help on method_descriptor in str: 3 4 str.split = split(...) 5 S.split([sep [,maxsplit]]) -> list of strings 6 7 Return a list of the words in the string S, using sep as the 8 delimiter string. If maxsplit is given, at most maxsplit 9 splits are done. If sep is not specified or is None, any 10 whitespace string is a separator and empty strings are removed 11 from the result. 12 13 >>>
- 结论
如果需要获取模块、类或方法等帮助信息,可以使用help方法,参数为对应的模块、类或方法的字符串表示
4、基本概念
(1)常量
略
(2)数
略
(3)字符串
- 单引号:‘This is string‘
- 双引号:"This is string"
- 三引号:‘’‘This is string‘’’或者"""This is string"""
- 转义
1 >>> #\‘转义为‘ 2 >>> print ‘What\‘s your name‘ 3 What‘s your name 4 >>> #\n转义为换行 5 >>> print ‘First line\nSecond line‘ 6 First line 7 Second line 8 >>> 9 >>>
- 自然字符串
如果想要指示某些不需要如转义符那样的特别处理的字符串,需要指定一个自然字符串。
自然字符串通过给字符串加上前缀r
或R
来指定。
1 >>> #\n转义为换行 2 >>> print ‘First line\nSecond line‘ 3 First line 4 Second line 5 >>> #\n不执行转义 6 >>> print r‘First line\nSecond line‘ 7 First line\nSecond line 8 >>>
- unicode字符串
当处理的字符串包含非英文字符时,使用unicode字符串,在字符串前面加u
1 >>> str1 = u‘Unicode String‘ 2 >>> print type(str1) 3 <type ‘unicode‘> 4 >>> print str1 5 Unicode String
- 字符串是不可变的
(4)变量
略
(5)标识符的命名
略
(6)数据类型
略
(7)对象
略
(8)逻辑行和物理行
物理行:编程时人能看到的一行
逻辑行:Python看到的单个语句
(9)缩进
略