# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 更多字符串和特殊方法
# - 前面我们已经学了类，在Python中还有一些特殊的方法起着非常重要的作用，这里会介绍一些特殊的方法和运算符的重载，以及使用特殊方法设计类

# ## str 类
# - 一个str对象是不可变的，也就是说，一旦创建了这个字符串，那么它的内容在认为不改变的情况下是不会变的
# - s1 = str()
# - s2 = str('welcome to Python')

a = 'zzz'
print(a)

b = str(12345)
b

b = str([1,3,4])
b

b = str('aaa')
b



# ## 创建两个对象，分别观察两者id
# - id为Python内存地址

print(id('a'))
print(id('a'))

a = 'a'
b = 'b'
print(id(a))
print(id(b))

a = 'a'
b = 'aaaaa'
print(id(a))
print(id(b))



# ## 处理字符串的函数
# - len
# - max
# - min
# - 字符串一切是按照ASCII码值进行比较

len('abc ')

i= 0
a = 'abc'
wlile i<len(a):
    print(a[i])
    i +=1



# ## 下角标运算符 []
# - 一个字符串是一个字符序列，可以通过索引进行访问
# - 观察字符串是否是一个可迭代序列  \__iter__

a = 'jingwang'
a[1]

a = 'jingwang'
a[1]
a.__iter__

a = 'jingwang'
a[-1]

a = 'jingwang'
a[::-1]

# ## 切片 [start: end]
# - start 默认值为0
# - end 默认值为-1

b = 'abcde'
b[1::2]

# ## 链接运算符 + 和复制运算符 *
# - \+ 链接多个字符串，同时''.join()也是
# - \* 复制多个字符串

's'+'b'

's'*2

for i in range(0,4):
    if i == 0 or i == 3:
        print('*'*5)
    else:
        print('*'+' '*3+'*')



# ## in 和 not in 运算符
# - in :判断某个字符是否在字符串内 
# - not in ：判断某个字符是否不在字符串内
# - 返回的是布尔值

a = '胡旺真傻'
b = '帅'
b not in a


def xxx(a,b):
    for i in a:
        if i == b:
            return True
    return False


path = '/Users/huwang/Downloads/mail.txt'
with open(path) as f:
    for i in range(5000):
        lines = f.readline()
        a = lines[0]
        if a == '1':
             print(lines)



# ## 比较字符串
# -  ==, !=, >=, <=, >, <
# - 依照ASCII码值进行比较

'abcse'   'se a ca'

# ## 测试字符串
# ![](../Photo/99.png)
# - 注意：
# > - isalnum() 中是不能包含空格，否则会返回False

b = 'abc'
b.isalnum()

b = '123'
b.isalnum()

b = 'zgh'
b.isidentifier()

b = 'abv'
b.isalpha()



a = '123abx'
def Check(a):
    N1,N2,N3 = 0,0,0
    for i in a:
        if i.isupper():
            N1 +=1
            elif i.islower():
                


# ## 搜索子串
# ![](../Photo/100.png)

import requests

url='http://www.4399dmw.com/haizeiwang/tupian'
HTML = requests.get(url).text
HTML.find('海贼王')

import requests

url='http://www.4399dmw.com/haizeiwang/tupian/'
HTML = requests.get(url).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)

# ## 转换字符串
# ![](../Photo/101.png)

a = 'Joker'
a.swapcase()



a = 'JokJer'
a.replace('J','K')

a = 'a v c d'
a.replace(' ',"")

b = '  abcd       '
b.lstrip()

b = '  abcd       '
b.rstrip()

# ## 删除字符串
# ![](../Photo/146.png)

b = " acde   "
b.rstrip()



# ## 格式化字符串
# ![](../Photo/103.png)

# ## EP:
# - 1
# ![](../Photo/104.png)
# - 2 
#     随机参数100个数字，将www.baidu.com/?page=进行拼接

# ## Python高级使用方法 -- 字符串
# - 我们经常使用的方法实际上就是调用Python的运算重载
# ![](../Photo/105.png)

a = 'a'
b = 'b'
a + b

a.__add__('b')

a.__mul__(10)

a * 10


# # Homework
# - 1
# ![](../Photo/106.png)

def check():
    a = input("格式：ddd_dd_dddd,d是数字：")
    if a ==123_12_123:
        print("valid ssn")
    else:
        print("invalid ssn")
check()

# - 2
# ![](../Photo/107.png)

a = str(input('>>'))
b = str(input('>>'))
"""
输入为字符串类型

"""
if a.find (b)!= -1:
    print('是')
else:
    print('不是')
    """
    if条件判断
    如果a.find(b)返回-1，说明a不是b的子串

    """


# - 3
# ![](../Photo/108.png)

def Cheak(a):
    N = len (a)
    n1,n2,n3 = 0,0,0
    for i in a:
        if i.isupper():
            n1 +=1
        elif i.islower():
            n2 +=1
        elif i.isdigit():
            n3 +=1
    if n1 ==0 :
        print('密码必须含有大写')
    if n2 ==0:
        print ('密码必须含有小写')
    if n3 == 0:
        print('密码必须含与数字')
    if N<=8:
        print('密码必须超过8位')
    check(a)   


# - 4
# ![](../Photo/109.png)

zm = input('输入字符串')
def counLettres():
    geshu = 0
    for i in zm:
        if i.isalpha():
            geshu +=1
            print(geshu)
counLettres()

# - 5
# ![](../Photo/110.png)

# - 6
# ![](../Photo/111.png)

zf = input('输入')
def reverse():
    return zf[::-1]
reverse()
    

# - 7
# ![](../Photo/112.png)

# - 8
# ![](../Photo/113.png)

# - 9
# ![](../Photo/114.png)

StarcoderdataJupyterScriptsDedupFiltered