Skip to content

Commit 4e4314b

Browse files
committed
py
1 parent 7a71693 commit 4e4314b

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

python_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
S = u'spam' # Python2.6中的Unicode字符串
137137
s1+s2, s1*3, s[i], s[i:j], len(s) # 字符串操作
138138
'a %s parrot' % 'kind' # 字符串格式化表达式
139-
'a {0} parrot'.format('kind') # 字符串格式化方法
139+
'a {1} {0} parrot'.format('kind', 'red')# 字符串格式化方法
140140
for x in s: print(x) # 字符串迭代,成员关系
141141
[x*2 for x in s] # 字符串列表解析
142142
','.join(['a', 'b', 'c']) # 字符串输出,结果:a,b,c
@@ -153,7 +153,7 @@
153153
str1.count('t') # 查找字符串出现的次数
154154
#上面所有方法都可用index代替,不同的是使用index查找不到会抛异常,而find返回-1
155155
str1.replace('old','new') # 替换函数,替换old为new,参数中可以指定maxReplaceTimes,即替换指定次数的old为new
156-
str1.strip();
156+
str1.strip(); # 默认删除空白符
157157
str1.strip('d'); # 删除str1字符串中开头、结尾处,位于 d 删除序列的字符
158158
str1.lstrip();
159159
str1.lstrip('d'); # 删除str1字符串中开头处,位于 d 删除序列的字符
@@ -171,7 +171,7 @@
171171

172172
#-- 索引和分片:
173173
S[0], S[len(S)–1], S[-1] # 索引
174-
S[1:3], S[1:], S[:-1], S[1:10:2] # 分片,第三个参数指定步长
174+
S[1:3], S[1:], S[:-1], S[1:10:2] # 分片,第三个参数指定步长,如`S[1:10:2]`是从1位到10位没隔2位获取一个字符。
175175

176176
#-- 字符串转换工具:
177177
int('42'), str(42) # 返回(42, '42')

python_sys.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# _*_ coding: utf-8 _*_
2+
import sys
3+
"""sys模块详细"""
4+
5+
sys.argv # 获得脚本的参数
6+
7+
sys.path # 查找扩展模块(Python源模块, 编译模块,或者二进制扩展)目录
8+
9+
sys.builtin_module_names # 查找内建模块
10+
11+
sys.modules # 查找已导入的模块
12+
sys.modules.keys()
13+
14+
sys.platform # 返回当前平台 出现如: "win32" "linux2" "darwin"等
15+
16+
sys.stdout # stdout 是一个类文件对象;调用它的 write 函数可以打印出你给定的任何字符串 stdout 和 stderr 都是类文件对象,但是它们都是只写的。
17+
它们都没有 read 方法只有 write 方法
18+
sys.stdout.write("hello")
19+
sys.stderr
20+
sys.stdin
21+
22+
sys.exit(1)
23+
24+
25+
26+
__import__("module_name") # 查找模块输出模块路径

0 commit comments

Comments
 (0)