<jupyter_start><jupyter_text>更多字符串和特殊方法- 前面我们已经学了类，在Python中还有一些特殊的方法起着非常重要的作用，这里会介绍一些特殊的方法和运算符的重载，以及使用特殊方法设计类  str 类- 一个str对象是不可变的，也就是说，一旦创建了这个字符串，那么它的内容在认为不改变的情况下是不会变的- s1 = str()- s2 = str('welcome to Python')<jupyter_code>b = str()
b<jupyter_output><empty_output><jupyter_text>创建两个对象，分别观察两者id- id为Python内存地址  处理字符串的函数- len- max- min- 字符串一切是按照ASCII码值进行比较<jupyter_code>len('abc')
i = 0
a = 'abc'
while i< len('abc'):
        print(a[i])
        i += 1<jupyter_output>a
b
c<jupyter_text>下角标运算符 []- 一个字符串是一个字符序列，可以通过索引进行访问- 观察字符串是否是一个可迭代序列  \__iter__  切片 [start: end]- start 默认值为0- end 默认值为-1<jupyter_code>a = 'zhangying'
a[::]
a = 'zhangying'
a[1:2]
a = 'https://www.w3cschool.cn/python3/python3-sting.html'
a[0:8] 
a[8:24]
b = 'abcdef'
b[0::2]
b[1::2]<jupyter_output><empty_output><jupyter_text>链接运算符 + 和复制运算符 *- \+ 链接多个字符串，同时''.join()也是- \* 复制多个字符串<jupyter_code>'a' + 'b' #字符串之间只能相加 字符串和数字只能相乘
for i in range(0,4):
    if i ==0 or i == 3:
        print('*'*5)
    else:
        print('*'+' '*3+'*')
        
'!'.join('abc')
a = '真美'
b = '美'
b in a
def z(a,b):
    for i in a:
        if i == b:
            return True
    
path = '/Users/Administrator/Desktop/mail.txt'
with open (path) as f:
    for i in range(5000):
        lines = f.readline()
        a = lines[0]
        if  a == '1':
            print(lines)
a='abcse'
a[-2: ]+a[0]+a[2]+a[0]
n='se a ca'
n[0:2]+n[3:5]+n[]<jupyter_output><empty_output><jupyter_text>in 和 not in 运算符- in :判断某个字符是否在字符串内 - not in ：判断某个字符是否不在字符串内- 返回的是布尔值  比较字符串-  ==, !=, >=, , <- 依照ASCII码值进行比较  测试字符串![](../Photo/99.png)- 注意：> - isalnum() 中是不能包含空格，否则会返回False<jupyter_code>a = 1234
isdigit(a):<jupyter_output><empty_output><jupyter_text>搜索子串![](../Photo/100.png)<jupyter_code>d = 'asadsa'
d.rfind('a')#从右开始找
d.find('a')#从左开始找<jupyter_output><empty_output><jupyter_text>转换字符串![](../Photo/101.png)<jupyter_code>import requests
ur1 = 'htpp://www.4399dmw.com/haizeiwang/tupian/'
HTML = requests.get(url).text
LIST = HTML.split('\n')
for i in LIST:
    if i.find('海贼王')!=-1:
        print(i)
while 1:
    i=2
    ur1 = 'htpp://www.4399dmw.com/haizeiwang/tupian/list-273-i.htm1'
    i +=1
    i>8
    HTML = requests.get(ur1).text
    LIST = HTML.split('\n')
    for line in LIST:
        if '.jpg' in line:
            lin2 = line.split('"')
       # print(lin2)
            for linee in lin2:
                if '.jpg' in linee:
                    print(linee)
                    break<jupyter_output><empty_output><jupyter_text>删除字符串![](../Photo/146.png)  格式化字符串![](../Photo/103.png)  EP:- 1![](../Photo/104.png)- 2     随机参数100个数字，将www.baidu.com/?page=进行拼接  Python高级使用方法 -- 字符串- 我们经常使用的方法实际上就是调用Python的运算重载![](../Photo/105.png)  Homework- 1![](../Photo/106.png)<jupyter_code>class ssn:
    a = input('请输入ddd-dd-dddd')
    if a==isdigit():
        print('Valid SSN')
    else:
        print('Invalid SSN')<jupyter_output>请输入ddd-dd-dddd12345678907<jupyter_text>- 2![](../Photo/107.png)<jupyter_code>def find():
    a = input(">>")
    b = input(">>")
    if a in b:
        print("子串")
    else:
        print("不是子串")
find()<jupyter_output>>>wecv
>>sdf
不是子串<jupyter_text>- 3![](../Photo/108.png)<jupyter_code>def check(password):
    N=len(password)
    N1,N2,N3=0,0,0
    for i in password:
        if i.isupper():  #检验大写
            N1 += 1
        elif i.islower():  #检验小写
            N2 += 1
        elif i.isdigit():   #检验数字
            N3 += 1
    if N1==0 and N2==0:
        print('密码必须含有字母')
    if N3<2:
        print('密码至少含有两个数字')
    if N<8:
        print('密码至少含有8位')
password = '<PASSWORD>'
check(password)<jupyter_output>密码至少含有8位<jupyter_text>- 4![](../Photo/109.png)<jupyter_code>def countletters(s):
        N=0
    for i in s:
        if i.isupper(): #检验大写
            N+=1
        if i.islower(): #检验小写
            N+=1
    print(N)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1855832241153342, 'fraction_numerical': 0.03748361730013106, 'mean_word_length': 2.917864476386037, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 53, 'https://': 1, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '572675', 'license': 'Apache-2.0', 'n_tokens_mistral': 2016, 'n_tokens_neox': 2073, 'n_words': 276, 'path': '7.24.ipynb', 'repo_name': 'woshimeimeide/mysqll', 'size': '3811'}