<jupyter_start><jupyter_text>字符串和常用数据结构 字符串：就是由零个或多个字符组成的有限序列<jupyter_code>def main():
    str1 = 'hello,world!'
    ####通过len函数计算字符串的长度
    print(len(str1)) # 12
    ####获得字符串首字母大写的拷贝
    print(str1.capitalize())
    ####获得字符串变大写后的拷贝
    print(str1.upper())
    ####从字符串中查找字串所在位置
    print(str1.find('or'))
    print(str1.find('shit'))
    ####检查字符串是以指定的字符串结尾
    print(str1.startswith('He'))
    print(str1.startswith('hel'))
    ####检查字符串是否以指定的字符串结尾
    print(str1.endswith('!'))
    # 将字符串以指定的宽度居中并在两侧填充指定的字符
    print(str1.center(50, '*'))
    # 将字符串以指定的宽度靠右放置左侧填充指定的字符
    print(str1.rjust(50, ' '))
    str2 = 'abc123456'
    # 从字符串中取出指定位置的字符(下标运算)
    print(str2[2])  # c
    # 字符串切片(从指定的开始索引到指定的结束索引)
    print(str2[2:5])  # c12
    print(str2[2:])  # c123456
    print(str2[2::2])  # c246
    print(str2[::2])  # ac246
    print(str2[::-1])  # 654321cba
    print(str2[-3:-1])  # 45
    # 检查字符串是否由数字构成
    print(str2.isdigit())  # False
    # 检查字符串是否以字母构成
    print(str2.isalpha())  # False
    # 检查字符串是否以数字和字母构成
    print(str2.isalnum())  # True
    str3 = '  <EMAIL> '
    print(str3)
    # 获得字符串修剪左右两侧空格的拷贝
    print(str3.strip())
    print(str3.lstrip())
    print(str3.rstrip())


    
main()<jupyter_output>12
Hello,world!
HELLO,WORLD!
7
-1
False
True
True
*******************hello,world!*******************
                                      hello,world!
c
c12
c123456
c246
ac246
654321cba
45
False
False
True
  <EMAIL> 
<EMAIL>
<EMAIL> 
  <EMAIL><jupyter_text>列表<jupyter_code>def main():
    list1 = [1, 3, 5, 7, 100]
    print(list1)
    list2 = ['hello'] * 5
    print(list2)
    # 计算列表长度(元素个数)
    print(len(list1))
    # 下标(索引)运算
    print(list1[0])
    print(list1[4])
    # print(list1[5])  # IndexError: list index out of range
    print(list1[-1])
    print(list1[-3])
    list1[2] = 300
    print(list1)
    # 添加元素
    list1.append(200)
    list1.insert(1, 400)
    list1 += [1000, 2000]
    print(list1)
    print(len(list1))
    # 删除元素
    list1.remove(3)
    if 1234 in list1:
        list1.remove(1234)
    del list1[0]
    print(list1)
    # 清空列表元素
    list1.clear()
    print(list1)


if __name__ == '__main__':
    main()<jupyter_output>[1, 3, 5, 7, 100]
['hello', 'hello', 'hello', 'hello', 'hello']
5
1
100
100
5
[1, 3, 300, 7, 100]
[1, 400, 3, 300, 7, 100, 200, 1000, 2000]
9
[400, 300, 7, 100, 200, 1000, 2000]
[]<jupyter_text>元组<jupyter_code>def main():
    # 定义元组
    
    t = ('骆昊', 38, True, '四川成都')
    print(t)
    # 获取元组中的元素
    print(t[0])
    print(t[3])
    # 遍历元组中的值
    for member in t:
        print(member)
    # 重新给元组赋值
    # t[0] = '王大锤'  # TypeError
    # 变量t重新引用了新的元组原来的元组将被垃圾回收
    t = ('王大锤', 20, True, '云南昆明')
    print(t)
    # 将元组转换成列表
    person = list(t)
    print(person)
    # 列表是可以修改它的元素的
    person[0] = '李小龙'
    person[1] = 25
    print(person)
    # 将列表转换成元组
    fruits_list = ['apple', 'banana', 'orange']
    fruits_tuple = tuple(fruits_list)
    print(fruits_tuple)


if __name__ == '__main__':
    main()<jupyter_output>('骆昊', 38, True, '四川成都')
骆昊
四川成都
骆昊
38
True
四川成都
('王大锤', 20, True, '云南昆明')
['王大锤', 20, True, '云南昆明']
['李小龙', 25, True, '云南昆明']
('apple', 'banana', 'orange')<jupyter_text>集合<jupyter_code>def main():
    set1 = {1, 2, 3, 3, 3, 2}
    print(set1)
    print('Length =', len(set1))
    set2 = set(range(1, 10))
    print(set2)
    set1.add(4)
    set1.add(5)
    set2.update([11, 12])
    print(set1)
    print(set2)
    set2.discard(5)
    # remove的元素如果不存在会引发KeyError
    if 4 in set2:
        set2.remove(4)
    print(set2)
    # 遍历集合容器
    for elem in set2:
        print(elem ** 2, end=' ')
    print()
    # 将元组转换成集合
    set3 = set((1, 2, 3, 3, 2, 1))
    print(set3.pop())
    print(set3)
    # 集合的交集、并集、差集、对称差运算
    print(set1 & set2)
    # print(set1.intersection(set2))
    print(set1 | set2)
    # print(set1.union(set2))
    print(set1 - set2)
    # print(set1.difference(set2))
    print(set1 ^ set2)
    # print(set1.symmetric_difference(set2))
    # 判断子集和超集
    print(set2 <= set1)
    # print(set2.issubset(set1))
    print(set3 <= set1)
    # print(set3.issubset(set1))
    print(set1 >= set2)
    # print(set1.issuperset(set2))
    print(set1 >= set3)
    # print(set1.issuperset(set3))


if __name__ == '__main__':
    main()<jupyter_output>{1, 2, 3}
Length = 3
{1, 2, 3, 4, 5, 6, 7, 8, 9}
{1, 2, 3, 4, 5}
{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12}
{1, 2, 3, 6, 7, 8, 9, 11, 12}
1 4 9 36 49 64 81 121 144 
1
{2, 3}
{1, 2, 3}
{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12}
{4, 5}
{4, 5, 6, 7, 8, 9, 11, 12}
False
True
False
True<jupyter_text>使用字典<jupyter_code># 字典的一切操作都是通过键名操作键值!!!!!!
# 字典是无序的,没有索引操作,除非转换成有序字典,

def main():
    scores = {'骆昊': 95, '白元芳': 78, '狄仁杰': 82}
    # 通过键可以获取字典中对应的值
    print(scores['骆昊'])
    print(scores['狄仁杰'])
    # 对字典进行遍历(遍历的其实是键再通过键取对应的值)
    for elem in scores:
        print('%s\t--->\t%d' % (elem, scores[elem]))
    # 更新字典中的元素
    scores['白元芳'] = 65
    scores['诸葛王朗'] = 71
    scores.update(冷面=67, 方启鹤=85)
    print(scores)
    if '武则天' in scores:
        print(scores['武则天'])
    print(scores.get('武则天'))
    # get方法也是通过键获取对应的值但是可以设置默认值
    print(scores.get('武则天', 60))
    # 删除字典中的元素
    print(scores.popitem())
    print(scores.popitem())
    print(scores.pop('骆昊', 100))
    # 清空字典
    scores.clear()
    print(scores)


if __name__ == '__main__':
    main()
def first():
    sum_ = 0
    errorsum_ = 0
    number1 = 0
    number2 = 0
    while True:
        number = int(input('请输入数字：'))
      
        if number > 0:
            sum_ += 1
            number1 = number + number1 
          
        elif number < 0:
            errorsum_ += 1
            number2 = number + number2 
            sum__ = number1 + number2
            error = sum__ / (sum_+errorsum_)
        else:
            break
    print("%f和%f均值" % (sum__,error))
first()
def Second():
    money = 10000
    list = []
    for i in range(1,14):
        money = money * 0.05 + money
        money_ = str(money)
        str_ = str(i)
        list.append(money)
      
        print('第' + str_ + '年的学费:'+money_)
    print(list)
 
    xuefei = list[0]+list[1]+list[2]+list[3]
    print('学费：%f' % xuefei)
Second()

def Therd():
    count_ = 0
    for i in range(100,1001):
        if i % 5 == 0 and i % 6 == 0 :
            count_ = count_ + 1
            print(i,end=' ')
            if count_ % 10 == 0:
                print()
Therd()
def Four():
    n = 0
    while n**2 < 12000:
        n += 1
    print (n)
Four()
  
def Four_():
    n = 0
    while n**3 < 12000:
        n += 1
    print(n)
Four_()
def five():
    
    sumber_ = 0
    for i in range(1,50001,1):
            sumber_ += 1/i
    print(sumber_)
five()
def six():
    sumb = 0
    for i in range(1,98,2):
        sumb += i / (i + 2)
    print(sumb)
six()
def seven():
    sumb = 0 
    for i in range(1,100000):
        sumb += 4 * (-1)**(i-1)/(2*i - 1)
    print(sumb)
seven()
def eight():
    for i in range(1,10001):
        k = 0
        for j in range(1,i):
            if (i%j==0):
                k+=j
            if i == k:
                print(i)
                break
eight()
def nine():
    count_ = 0
    for i in range(1,8,1):
        for j in range(1,8,1):
            sumb = i*10 + j
            count_ += 1
            print(sumb)
    print('个数：%f'%count_)
nine()<jupyter_output>11
12
13
14
15
16
17
21
22
23
24
25
26
27
31
32
33
34
35
36
37
41
42
43
44
45
46
47
51
52
53
54
55
56
57
61
62
63
64
65
66
67
71
72
73
74
75
76
77
个数：49.000000
{'fraction_non_alphanumeric': 0.1687314839752222, 'fraction_numerical': 0.08806894694317263, 'mean_word_length': 2.3008888888888888, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '327600', 'license': 'Apache-2.0', 'n_tokens_mistral': 3977, 'n_tokens_neox': 3744, 'n_words': 702, 'path': 'dfzy02.ipynb', 'repo_name': 'baicha12/snow-fox', 'size': '7476'}