既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
str_gbk = str.encode(“GBK”)
print(str)
print(“UTF-8 编码:”, str_utf8)
print(“GBK 编码:”, str_gbk)
print(“UTF-8 解码:”, str_utf8.decode(‘UTF-8’,‘strict’))
print(“GBK 解码:”, str_gbk.decode(‘GBK’,‘strict’))
结果如下:
牛客教程
UTF-8 编码: b’\xe7\x89\x9b\xe5\xae\xa2\xe6\x95\x99\xe7\xa8\x8b’
GBK 编码: b’\xc5\xa3\xbf\xcd\xbd\xcc\xb3\xcc’
UTF-8 解码: 牛客教程
GBK 解码: 牛客教程
以上可以看出编码的重要性。
## find()
### 描述
find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果指定范围内如果包含指定索引值,返回的是索引值在字符串中的起始位置。如果不包含索引值,返回-1。
find()方法语法:
| | |
| --- | --- |
| 1 | `str.find(str, beg=``0``, end=len(string))` |
### 参数
* str -- 指定检索的字符串
* beg -- 开始索引,默认为0。
* end -- 结束索引,默认为字符串的长度。
### 返回值
如果包含子字符串返回开始的索引值,否则返回-1。
---
以下实例展示了find()方法的实例:
str1 = “Nowcoder example…wow!!!”
str2 = “exam”;
print (str1.find(str2))
print (str1.find(str2, 5))
print (str1.find(str2, 10))
结果如下:
9
9
-1
## index()
### 描述
index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,该方法与 python find()方法一样,只不过如果str不在 string中会报一个异常。
index()方法语法:
| | |
| --- | --- |
| 1 | `str.index(str, beg=``0``, end=len(string))` |
### 参数
* str -- 指定检索的字符串
* beg -- 开始索引,默认为0。
* end -- 结束索引,默认为字符串的长度。
### 返回值
如果包含子字符串返回开始的索引值,否则抛出异常。
---
以下实例展示了index()方法的实例:
str1 = “Nowcoder example…wow!!!”
str2 = “exam”;
print (str1.index(str2))
print (str1.index(str2, 5))
print (str1.index(str2, 10))
结果如下:
Traceback (most recent call last):
File “C:/work/P_workspace/cainiao/cainiao/customize/demo.py”, line 6, in
print (str1.index(str2, 10))
ValueError: substring not found
9
9
index()函数还是比较重要的,可以了解下。
## List index()
### 描述
index() 函数用于从列表中找出某个值第一个匹配项的索引位置。
index()方法语法:
| | |
| --- | --- |
| 1 | `list.index(x[, start[, end]])` |
### 参数
* x-- 查找的对象。
* start-- 可选,查找的起始位置。
* end-- 可选,查找的结束位置。
### 返回值
该方法返回查找对象的索引位置,如果没有找到对象则抛出异常。
---
以下实例展示了 index()函数的使用方法:
list1 = [‘Google’, ‘Nowcoder’, ‘Taobao’]
print (‘Nowcoder 索引值为’, list1.index(‘Nowcoder’))
print (‘Taobao 索引值为’, list1.index(‘Taobao’))
Nowcoder 索引值为 1
Taobao 索引值为 2
## join()
### 描述
Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
join()方法语法:
| | |
| --- | --- |
| 1 | `str.join(sequence)` |
### 参数
* sequence -- 要连接的元素序列。
### 返回值
返回通过指定字符连接序列中元素后生成的新字符串。
---
以下实例展示了join()的使用方法:
s1 = “-”
s2 = “”
seq = (“n”, “o”, “w”, “c”, “o”, “d”, “e”, “r”) # 字符串序列
print (s1.join( seq ))
print (s2.join( seq ))
结果如下:
n-o-w-c-o-d-e-r
nowcoder
**这个函数挺重要的,平时用的非常多。**
## len()
### 描述
Python len() 方法返回对象(字符、列表、元组等)长度或项目个数。
len()方法语法:
| | |
| --- | --- |
| 1 | `len( s )` |
### 参数
* s -- 对象。
### 返回值
返回对象长度。
---
以下实例展示了 len() 的使用方法:
str = “nowcoder”
len(str) # 字符串长度
8
l = [1,2,3,4,5]
len(l) # 列表元素个数
5
## lstrip()
### 描述
lstrip() 方法用于截掉字符串左边的空格或指定字符。
lstrip()方法语法:
| | |
| --- | --- |
|
1
|
`str.lstrip([chars])`
|
### 参数
* chars --指定截取的字符。
### 返回值
返回截掉字符串左边的空格或指定字符后生成的新字符串。
---
以下实例展示了lstrip()的使用方法:
str = " this is string example…wow!!! ";
print( str.lstrip() );
str = “88888888this is string example…wow!!!8888888”;
print( str.lstrip(‘8’) );
结果如下:
this is string example…wow!!!
this is string example…wow!!!8888888
## max()
### 描述
max() 方法返回字符串中最大的字母。
max()方法语法:
| | |
| --- | --- |
| 1 | `max(str)` |
### 参数
* str -- 字符串。
### 返回值
返回字符串中最大的字母。
---
以下实例展示了max()函数的使用方法:
str = “nowcoder”
print ("最大字符: " + max(str))
结果如下:
最大字符: w
## List max()方法
### 描述
max() 方法返回**列表**元素中的最大值。
max()方法语法:
| | |
| --- | --- |
| 1 | `max(list)` |
### 参数
* list -- 要返回最大值的列表。
### 返回值
返回列表元素中的最大值。
---
以下实例展示了 max()函数的使用方法:
list1, list2 = [‘Google’, ‘Nowcoder’, ‘Taobao’], [456, 700, 200]
print ("list1 最大元素值 : ", max(list1))
print ("list2 最大元素值 : ", max(list2))
list1 最大元素值 : Taobao
list2 最大元素值 : 700
## replace()
### 描述
replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。
replace()方法语法:
| | |
| --- | --- |
|
1
|
`str.replace(old,``new``[, max])`
|
### 参数
* old -- 将被替换的子字符串。
* new -- 新字符串,用于替换old子字符串。
* max -- 可选字符串, 替换不超过 max 次
### 返回值
返回字符串中的 old(旧字符串) 替换成 new(新字符串)后生成的新字符串,如果指定第三个参数max,则替换不超过 max 次。
---
以下实例展示了replace()函数的使用方法:
str = “www.niuke.com”
print (“牛客教程旧地址:”, str)
print (“牛客教程新地址:”, str.replace(“niuke”, “nowcoder”))
str = “this is string example…wow!!!”
print (str.replace(“is”, “was”, 3))
结果如下:
牛客教程旧地址: www.niuke.com
牛客教程新地址: www.nowcoder.com
thwas was string example…wow!!!
## strip()
### 描述
Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)或字符序列。
**注意:**该方法只能删除开头或是结尾的字符,不能删除中间部分的字符。
strip()方法语法:
| | |
| --- | --- |
| 1 | `str.strip([chars]);` |
### 参数
* chars -- 移除字符串头尾指定的字符序列。
### 返回值
返回移除字符串头尾指定的字符序列生成的新字符串。
---
以下实例展示了 strip() 函数的使用方法:
str = “this is string example…wow!!!”
print (str.strip( ‘*’ )) # 指定字符串 *
this is string example…wow!!!
从结果上看,可以注意到中间部分的字符并未删除。
str = “123abcnowcoder321”
print (str.strip( ‘12’ )) # 字符序列为 12
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
以下实例展示了 strip() 函数的使用方法:
str = "*****this is **string** example....wow!!!*****"
print (str.strip( '*' )) # 指定字符串 *
this is **string** example....wow!!!
从结果上看,可以注意到中间部分的字符并未删除。
str = "123abcnowcoder321"
print (str.strip( '12' )) # 字符序列为 12
[外链图片转存中...(img-9p3ZrVpW-1715612795124)]
[外链图片转存中...(img-5qjWYOen-1715612795124)]
[外链图片转存中...(img-nDJmJ2A5-1715612795124)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**