|  | 
| 7 | 7 |  help(obj.func) # 查询obj.func的具体介绍和用法 | 
| 8 | 8 | 
 | 
| 9 | 9 | #-- 测试类型的三种方法,推荐第三种 | 
| 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") | 
| 13 | 16 | 
 | 
| 14 | 17 | #-- Python数据类型:哈希类型、不可哈希类型 | 
| 15 | 18 |  # 哈希类型,即在原地不能改变的变量类型,不可变类型。可利用hash函数查看其hash值,也可以作为字典的key | 
|  | 
| 146 | 149 |  str1.count('t') # 查找字符串出现的次数 | 
| 147 | 150 |  #上面所有方法都可用index代替,不同的是使用index查找不到会抛异常,而find返回-1 | 
| 148 | 151 |  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 删除序列的字符 | 
| 150 | 158 |  str1.startswith('start') # 是否以start开头 | 
| 151 | 159 |  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() # 判断字符串是否全为字符、数字、小写、大写 | 
| 153 | 161 | 
 | 
| 154 | 162 | #-- 三重引号编写多行字符串块,并且在代码折行处嵌入换行字符\n | 
| 155 | 163 |  mantra = """hello world | 
|  | 
| 166 | 174 |  float('4.13'), str(4.13) # 返回(4.13, '4.13') | 
| 167 | 175 |  ord('s'), chr(115) # 返回(115, 's') | 
| 168 | 176 |  int('1001', 2) # 将字符串作为二进制数字,转化为数字,返回9 | 
| 169 |  | - bin(13), oct(13), hex(13) # 将整数转化为二进制/八进制/十六进制字符串,返回('1001', '0o15', '0xd') | 
|  | 177 | + bin(13), oct(13), hex(13) # 将整数转化为二进制/八进制/十六进制字符串,返回('0b1101', '015', '0xd') | 
| 170 | 178 | 
 | 
| 171 | 179 | #-- 另类字符串连接 | 
| 172 | 180 |  name = "wang" "hong" # 单行,name = "wanghong" | 
|  | 
0 commit comments