Skip to content

Commit 91728dc

Browse files
authored
Merge pull request xianhu#6 from zhisheng17/master
update python_base.py
2 parents 9f29890 + 59287d8 commit 91728dc

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

python_base.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
help(obj.func) # 查询obj.func的具体介绍和用法
88

99
#-- 测试类型的三种方法,推荐第三种
10-
if type(L) == type([]): print("L is list")
11-
if type(L) == list: print("L is list")
12-
if isinstance(L, list): print("L is list")
10+
if type(L) == type([]):
11+
print("L is list")
12+
if type(L) == list:
13+
print("L is list")
14+
if isinstance(L, list):
15+
print("L is list")
1316

1417
#-- Python数据类型:哈希类型、不可哈希类型
1518
# 哈希类型,即在原地不能改变的变量类型,不可变类型。可利用hash函数查看其hash值,也可以作为字典的key
@@ -146,10 +149,15 @@
146149
str1.count('t') # 查找字符串出现的次数
147150
#上面所有方法都可用index代替,不同的是使用index查找不到会抛异常,而find返回-1
148151
str1.replace('old','new') # 替换函数,替换old为new,参数中可以指定maxReplaceTimes,即替换指定次数的old为new
149-
str1.strip(); str1.lstrip(); str1.rstrip(); str1.strip('d'); str1.lstrip('d'); str1.rstrip('d')
152+
str1.strip();
153+
str1.strip('d'); # 删除str1字符串中开头、结尾处,位于 d 删除序列的字符
154+
str1.lstrip();
155+
str1.lstrip('d'); # 删除str1字符串中开头处,位于 d 删除序列的字符
156+
str1.rstrip();
157+
str1.rstrip('d') # 删除str1字符串中结尾处,位于 d 删除序列的字符
150158
str1.startswith('start') # 是否以start开头
151159
str1.endswith('end') # 是否以end结尾
152-
str1.isalnum(); str1.isalpha(); str1.isdigit(); str1.islower(); str1.isupper() # 判断字符串是否全为字符、数字、大写、小写
160+
str1.isalnum(); str1.isalpha(); str1.isdigit(); str1.islower(); str1.isupper() # 判断字符串是否全为字符、数字、小写、大写
153161

154162
#-- 三重引号编写多行字符串块,并且在代码折行处嵌入换行字符\n
155163
mantra = """hello world
@@ -166,7 +174,7 @@
166174
float('4.13'), str(4.13) # 返回(4.13, '4.13')
167175
ord('s'), chr(115) # 返回(115, 's')
168176
int('1001', 2) # 将字符串作为二进制数字,转化为数字,返回9
169-
bin(13), oct(13), hex(13) # 将整数转化为二进制/八进制/十六进制字符串,返回('1001', '0o15', '0xd')
177+
bin(13), oct(13), hex(13) # 将整数转化为二进制/八进制/十六进制字符串,返回('0b1101', '015', '0xd')
170178

171179
#-- 另类字符串连接
172180
name = "wang" "hong" # 单行,name = "wanghong"

0 commit comments

Comments
 (0)