欢迎光临散文网 会员登陆 & 注册

Python课程天花板,Python入门+Python爬虫+Python数据分析

2023-06-26 14:34 作者:MEMORIA丶Y  | 我要投稿

1、退出:exit() ctrl+z:死机情况

2、-*-codeing=utf-8-*-:打印输出不会出现中文乱码

3:、格式化输出

age=18

print("我的年龄是:%d岁"%age)

print("我的名字是%s,我的国籍%s"%("小张","中国"))

print("www","baidu","com",sep=".")

结果:www.baidu.com


%s:通过str()字符串转换来格式化

%d:有符号十进制整数


5.条件判断语句 P5 - 00:01

1.换行输出

如果有\n那么此时\n后的内容会在另外一行显示

2.输入

  • 如何知道输出的是什么类型

a = 10

print(type(a))

a= "abc"

print.....

  • input输入的默认是什么类型

a = input("输入:")

print(type(a))

print("输入了一个数字:%s"%a)

  • 想把输入字符串变成数字的时候
a =int("123")
print(type(a))
b=a +100
print(b)

%s变成%d





3.判断语句

  • 条件判断语句

指定任何非0和非空值为True,0或None为False

if语句用于控制程序的执行

if True:
    print("True")
else:
    print("False")
冒号不能丢  缩进 


score =87
if score>=90 and score<=100:
    print("等级A")
else:
    if score>=80 and score<90:
        print("等级为B")
    print("等级为C")


层层嵌套 先计算里面的 再跳出来


score =67
if score>=90 and score<=100:
    print("等级A")
elif  score>=80 and score<90:
    print("等级为B")
elif  score>=70 and score<80:
    print("等级为D")
else:
    print("等级为C")

 结果:等级为C


import random 引入随机库



6.循环控制语句 P6 - 00:07


1.for 循坏


2、while

count +=1 要有一个增量循坏

else :当while条件不满足的时候执行


i = 0
while i<10:
    i=i+1
    print("-"*30)
    if i==6:
        break #结束整个while循坏
    print(i)

i = 0
while i<10:
    i=i+1
    print("-"*30)
    if i==6:
        continue #结束本次循坏包括里面的语句
    print(i)


7.字符串 P7 - 00:02


a = "I'm a studunt"
a = 'I\'m a studunt'
print(a)

a = "kk said \"I like you\""
a = 'kk said "I like you"'
print(a)
str = "chengdu"
'''
print(str)
print(str[0])
print(str[0:6])   
print(str[1:7:2])     #[起始位置:结束位置:步进值]
'''
print(str[5:])   #空的表示到最后的
print(str[:5])   #空的表示从最前

print(str +",你好") #字符串连接,使用+
print(str * 3)
print("hello\nchengdu")   #使用反斜杠,实现转义字符的功能
print(r"hello\nchengdu")  #hello\nchengdu   r表示直接显示原始字符串,直接输出不进行转义
namelist = []    #定义一个空的列表



8.列表(上) P8 - 09:19



namelist = []    #定义一个空的列表

namelist = ["小余","小肖","小李"]

'''
testlist = [1,"测试"]  #列表中可以存储混合类型
print(type(testlist[0]))
print(type(testlist[1]))
print(namelist[0])
print(namelist[1])
print(namelist[2])
'''
'''
for name in namelist:
    print(name)
'''
#print(len(namelist))    #len()可以得到列表的长度
length = len(namelist)
i = 0
while i<length:
    print(namelist[i])
    i=i+1


9.列表(下) P9 - 03:38



10.元组_字典(上) P10 - 00:01





11.字典(下)_集合 P11 - 00:03





12.函数 P12 - 00:09


1、定义函数

格式:

def 函数名():

代码


13.文件操作 P13 - 00:14


1、文件打开与关闭

打开文件:

open(文件名,访问模式)

f = open('test.txt','w')


14.异常处理 P14 - 00:03



14.异常处理 P14 - 18:28



15.Python爬虫介绍 P15 - 01:48





















Python课程天花板,Python入门+Python爬虫+Python数据分析的评论 (共 条)

分享到微博请遵守国家法律