<jupyter_start><jupyter_text>更多字符串和特殊方法- 前面我们已经学了类，在Python中还有一些特殊的方法起着非常重要的作用，这里会介绍一些特殊的方法和运算符的重载，以及使用特殊方法设计类  str 类- 一个str对象是不可变的，也就是说，一旦创建了这个字符串，那么它的内容在认为不改变的情况下是不会变的- s1 = str()- s2 = str('welcome to Python')<jupyter_code>a = 100
b = str(a)
c = 'joker'
print(b + c)

id (a)
a = 100
b = 100
print(id(a),id(b))<jupyter_output>140714872774560 140714872774560<jupyter_text>创建两个对象，分别观察两者id- id为Python内存地址  处理字符串的函数- len- max- min- 字符串一切是按照ASCII码值进行比较<jupyter_code>c = 'Joker'
d = 'HAHa'
max(c,d)<jupyter_output><empty_output><jupyter_text>下角标运算符 []- 一个字符串是一个字符序列，可以通过索引进行访问- 观察字符串是否是一个可迭代序列  \__iter__<jupyter_code>for i in 'joker':
    print(i)
c = 'joker'
i = 0
while i < len (c):
    print (c[i])
    i +=1

c[0]#索引从0开始#索引越界
print (c)
c[-1]#len-1
h = 'hei ha hei'#空格也算<jupyter_output><empty_output><jupyter_text>切片 [start: end]- start 默认值为0- end 默认值为-1<jupyter_code>a = '洋洋和建建要洗澡了，可是洋洋嫌弃建建黑，但是建建洗澡不脱衣服'
print(len)
a[::-1]#从0到25 buchangweiyi，-1时倒着取
a[0:3][::-1]
def Search (index):
    path = '/Users/dell/Desktop/pathon2/pathon基础/mail.txt'
    with open(file=path,mode='r') as f:
        for i in range(1000):
            line = f.readline()
            new_line = line[0:index+1]
            if new_line[-1] == '@':
                print(new_line[:-1])
            if new_line = chr()     
            
Search(5)<jupyter_output>kcqer
bn922
11000
tenQQ
jiw23
65464
max74
55555
lw45j
qerjh
jijij
45646
zxqcw
djzjh<jupyter_text>链接运算符 + 和复制运算符 *- \+ 链接多个字符串，同时''.join()也是- \* 复制多个字符串<jupyter_code>for i in range(2,8):
a = 'a'
b = 'b'
a+b

'*'.join('joker')<jupyter_output><empty_output><jupyter_text>in 和 not in 运算符- in :判断某个字符是否在字符串内 - not in ：判断某个字符是否不在字符串内- 返回的是布尔值<jupyter_code>'jo' not in 'jokwe'<jupyter_output><empty_output><jupyter_text>比较字符串-  ==, !=, >=, , <- 依照ASCII码值进行比较<jupyter_code>'a' > 'b'<jupyter_output><empty_output><jupyter_text>测试字符串![](../Photo/99.png)- 注意：> - isalnum() 中是不能包含空格，否则会返回False<jupyter_code>a = 'joker'
a.isalnum()#只有字母数字
mima = input('请输入一串密码')
lenght = len(mima)
daxie = 0
xiaoxie = 0
shuzi = 0
if lenght<=8:
    print('密码必须大于8位')
for i in mima:
    if i.isupper():
        daxie +=1
    if i.islower():
        xiaoxie +=1
    if i.isdigit():
        shuzi +=1
if daxie == 0:
    print('密码必须有大写')
if xiaoxie == 0:
    print('密码必须有小写')
if shuzi == 0:
    print ('密码必须有数字')<jupyter_output>请输入一串密码wyy116558
密码必须有大写<jupyter_text>搜索子串![](../Photo/100.png)<jupyter_code>b = 'foifej0'
b.count('f')
b = 'iofjofo'
b.find('i')#返回的时索引，没有显示-1
b.rfind#从右边查，左边数
def Search (index):
    path = '/Users/dell/Desktop/pathon2/pathon基础/mail.txt'
    with open(file=path,mode='r') as f:
        for i in range(1000):
            line = f.readline()
            if line.find('45813526') != -1:
                print(line)
            break<jupyter_output><empty_output><jupyter_text>转换字符串![](../Photo/101.png)<jupyter_code>a = 'kfvlkmv'
a.replace('mv','jk')<jupyter_output><empty_output><jupyter_text>删除字符串![](../Photo/146.png)  格式化字符串![](../Photo/103.png)<jupyter_code>'*'.center(1)
for i in range(0, rows):
    for j in range(0, rows):
        if i != 0 and i != rows - 1:
            if j == 0 or j == rows - 1:
                 print (" * ")
            else:
                 print "   "
        else:
            print (" * ")
        j += 1
    i += 1
    print ("\n")<jupyter_output><empty_output><jupyter_text>EP:- 1![](../Photo/104.png)- 2     随机参数100个数字，将www.baidu.com/?page=进行拼接  Python高级使用方法 -- 字符串- 我们经常使用的方法实际上就是调用Python的运算重载![](../Photo/105.png)<jupyter_code>a.__add__(b)
a = 'abcd'
while i <:
    i<jupyter_output><empty_output><jupyter_text>Homework- 1![](../Photo/106.png)<jupyter_code>def A():
    d = input('请输入一个社会安全号码：')
    a = d[0:3]
    b = d[4:6]
    c = d[7:]
    if a.isdigit() == 1 and b.isdigit()== 1 and c.isdigit() == 1:#判断输入的号码中只含有数字字符，若有返回true，用数字1表示
        print('Valid SSN')
    else:
        print('Invalid SSN')
A()<jupyter_output>请输入一个社会安全号码：562-52-4591
Valid SSN<jupyter_text>- 2![](../Photo/107.png)<jupyter_code>def B():
    m = input('请输入第一组字符串：')
    n = input('请输入第二组字符串：')
    if n.find(m) >= 0:#在n字符串中寻找m字符串
        print('True')
    else:
        print('False')
    
B()<jupyter_output>请输入第一组字符串：ji
请输入第二组字符串：pljihu
True<jupyter_text>- 3![](../Photo/108.png)<jupyter_code>def C():
    mima = input('请输入一串密码')
    lenght = len(mima)
    daxie = 0
    xiaoxie = 0
    shuzi = 0
    if lenght<8:#判断字符的长度
        print('invalid password')
    for i in mima:
        if i.isupper():#判断密码中是否存在大写英文字母
            daxie +=1
        if i.islower():#判断密码中是否存在小写英文字母
            xiaoxie +=1
        if i.isdigit():#判断密码中是否存在数字
            shuzi +=1
    if lenght >= 8 and daxie != 0 and xiaoxie != 0 and shuzi > 2:
        print('valid password')

C()<jupyter_output>请输入一串密码k<PASSWORD><jupyter_text>- 4![](../Photo/109.png)<jupyter_code>def countLetters(s):
    m_d = 0#大写字母计数
    m_x = 0#小写字母计数
    for i in s:
        if i.isupper():#判断是否含大写字母
            m_d +=1
        if i.islower():#判断是否含小写字母  
            m_x +=1
            n = (m_d + m_x)#定义一个字母表示大小写数量和
    print(n)       
countLetters('ndioJIKLNsvo45')<jupyter_output>12<jupyter_text>- 5![](../Photo/110.png)<jupyter_code>def getNumber(uppercaseLetter):
    x1 = 0
    x2 = 0
    number = input('请输入一个电话号码：')
    for i in uppercaseLetter:
        if i.isupper():#判断是否含大写字母
            x1 +=1
        if i.islower():#判断是否含小写字母  
            x2 +=1<jupyter_output><empty_output><jupyter_text>- 6![](../Photo/111.png)<jupyter_code>def reverse(s):
    s.reverse()
    print(s)
 reverse(['j','n','k'])<jupyter_output>['k', 'n', 'j']<jupyter_text>- 7![](../Photo/112.png) - 8![](../Photo/113.png)<jupyter_code>def D():
    x = input('ISBN-13:')
    d = int(x[0]+3*x[1]+x[2]+3*x[3]+x[4]+3*x[5]+x[6]+3*x[7]+x[8]+3*x[9]+x[10]+3*x[11])%10
    d13 = 10-d
    if d13 == 10:
        d13 = 0
    y = x+str(d13)
    print('The ISBN-13 number is',y)
D()<jupyter_output>ISBN-13:978013213079
The ISBN-13 number is 9780132130791
{'fraction_non_alphanumeric': 0.17816770710308757, 'fraction_numerical': 0.05247173949721613, 'mean_word_length': 3.168776371308017, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '273000', 'license': 'Apache-2.0', 'n_tokens_mistral': 3258, 'n_tokens_neox': 3255, 'n_words': 426, 'path': '7.24.ipynb', 'repo_name': 'yangbaibai/python0', 'size': '5925'}