day3

import time
num=0
#第一层循环
while True:
    print('第一层循环')

    #第二层循环
    while True:
        print('第二层循环')
        #第三层循环
        while True:
            time.slepp(1)
            print("第三层循环")
            print(num)
            num+=1
            continue
            print('结束本次循环,继续进行本次循环')



            #
            #list=[1,2,3]
            #for x in list1;
            #     print(x)e
            #rang (0,10)  0---(10-1)
            #range(开始位置,结束位置)
            #0-9
            print(range(10))

            for x in  range (1,10):
                print(x)



str1='墙里的想着出去,墙外的人想着进来'
#     0 1 2 34 56 89 .16
#索引取值
print(len(str1))
print(str1[9])#

#切片
#str1中的"墙外的人”四个字
#range(8,12)#8-11
#[8:12]顾头不顾尾  尾巴—1
print(str1[8:12])#q墙外的人
# 长度len
print(len(str1))

# 成员运算in|not in
print('' in str1)  # True, 判断进字是否在str1里面
print('' not in str1)  # False

# 移除空白strip
username = input('请输入用户名')
print(username)
# 移除username两边的空格
username = username.strip()
print(username)

str2 = '墨:菲:定:律'
# 切分split(切分的规则)
# list1 = []
# for x in str2:
#     print(x)
#     list1.append(x)
# print(list1)
list1 = str2.split(':')
print(list1)

# lower&upper 大小写
str3 = 'aabbcc'
# 把str3的字母都变成小写
lower_str3 = str3.lower()
print(lower_str3)  # aabbcc

# 把str3的字母都变成大写
upper_str3 = str3.upper()
print(upper_str3)  # AABBCC

# startswith&endswith 判断字符的开头或结尾是否是什么
str4 = 'tank是一个文质彬彬的靓仔'
print(str4.starswich('tank'))  # True
print(str4.startswich('DSB'))  # False

print(str4.endswith('靓仔'))  # True
print(str4.endswith('sb'))  # False

# replace: 替换。replace(旧, 新)
str5 = '吕连杰说,有个人很帅啊,他是徐峰啊!'
str5 = str5.replace('徐峰','tank')
print(str5)

# isdigit: 判断字符是否是数字
str6 = '24124141'
print(str6.isdigit())  # True
list=['tank',18,'tank']
#append
list.append('male')
print(list)
#count:计算机列表中值的数量
print(list1.count('tamk'))#2
'''字典的内置方法:
'''
#dict1
#   name='tank'
#   age=18
dict={'name':'tank','age':18}
print(dict1['name'])
#若key不存在则报错
#print(dict['name'])
#get特点是key没有默认返回None
print(dict1.get('name1'))#None

'''文本读写
'''
#写文件
#with open('安财贸.txt','w',encoding='utf-8')as  f
#    str1='tank很帅,真的啊!'
#    f.wite(str1)
#读文件
with open('安财贸.txt')
    # 长度len
    print(len(str1))

    # 成员运算in|not in
    print('' in str1)  # True, 判断进字是否在str1里面
    print('' not in str1)  # False

    # 移除空白strip
    username = input('请输入用户名')
    print(username)
    # 移除username两边的空格
    username = username.strip()
    print(username)

    str2 = '墨:菲:定:律'
    # 切分split(切分的规则)
    # list1 = []
    # for x in str2:
    #     print(x)
    #     list1.append(x)
    # print(list1)
    list1 = str2.split(':')
    print(list1)

    # lower&upper 大小写
    str3 = 'aabbcc'
    # 把str3的字母都变成小写
    lower_str3 = str3.lower()
    print(lower_str3)  # aabbcc

    # 把str3的字母都变成大写
    upper_str3 = str3.upper()
    print(upper_str3)  # AABBCC

    # startswith&endswith 判断字符的开头或结尾是否是什么
    str4 = 'tank是一个文质彬彬的靓仔'
    print(str4.starswich('tank'))  # True
    print(str4.startswich('DSB'))  # False

    print(str4.endswith('靓仔'))  # True
    print(str4.endswith('sb'))  # False

    # replace: 替换。replace(旧, 新)
    str5 = '吕连杰说,有个人很帅啊,他是徐峰啊!'
    str5 = str5.replace('徐峰', 'tank')
    print(str5)

    # isdigit: 判断字符是否是数字
    str6 = '24124141'
    print(str6.isdigit())  # True

    list1 = ['tank', 18, 'tank']

    # append
    list1.append('male')
    print(list1)

    # count: 计算列表中值的数量
    print(list1.count('tank'))  # 2

    '''
    字典的内置方法

    '''
    # dict1:
    #     name = 'tank'
    #     age = 18
    dict1 = {'name': 'tank', 'age': 18}

    print(dict1['name'])
    # 若key不存在则报错
    # print(dict1['name'])

    # get特点是key没有默认返回None
    print(dict1.get('name1'))  # None

    '''
    文本读写

    字符编码
         美国:
              ASCCI
         中国:
              GBK
         日本...

         总结:
    '''
    # 写文件
    # with open('安财贸.txt', 'w', encoding='utf-8) as f:
    #     str1 = 'tank很帅,真的啊!'
    #     f.write(str1)

    # 读文件
    with open('安财贸.txt', 'r', encoding='utf-8') as f:
        str1 = f.read()
        print(str1)

    '''
    读写二进制流数据
    '''
    with open('xiao泽.mp4', 'r') as f:
        data = f.read()
        print(data)

    '''
    爬取cang老师图片,并保存到本地.
         1.导入request模块
               下载:
                   注意:必须联网
                   方式一:
                         pip3 install requests
                   方式二:
                         file->settings->project->interpreter->'绿色的'
                         在输入框内输入 ---> requests --> install package
               import requests
         2.使用requests爬取图片并保存
             - 1)下载图片
             - 2)保存图片

    '''
    import requests

    # 1)下载图片
    # requests.get('数据的连接')
    # 往cang老师图片地址发送请求获取响应数据
    response = requests.get(
        'https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268%3Bg%3D0/sign=4c9bf08f04f41bd5da53eff269e1e6f6/d439b6003af33a87d8d517becc5c10385243b5dd.jpg')

    # content就是获取图片的二进制流数据
    print(response.content)
    # 2)保存数据
    # 读取二进制流数据 write + bytes   wb
    with open('cang老师.jpg', 'wb') as f:
        # f.write(传入二进制流的数据)
        f.write(response.content)

 

posted @ 2019-09-25 21:45  陈小跳  阅读(90)  评论(1)    收藏  举报