python
Python提供了很多优秀的
第三⽅的框架和库,⽐如全栈WEB框架Django,轻量级WEB框架Flask,异步框架FastApi,以及AsyncioIO等。
python设计核心思想:一切皆对象。
python是函数式编程语言,同时又是面向对象的编程语言。
写Java 、go、 pychon语言所用的软件
python编码与解码
四种数据类型
int :年龄
str :姓名
bool:真或者假
float :薪资
注释
多行注释: ’’’
‘’’
单行注释: #
print()输出
变量的规则
1、变量只能是字⺟,数字,和下划线
2、变量名的第⼀个字符不能是数字
3、如果变量名称是多个字符串,建议使⽤驼峰式的命名规则
4、定义变量名称尽量的通俗易懂,⼀⾔以蔽之。
变量的生命周期:当一个变量调用的时候会在内存当中给这个变量分配地址,比如age会分配12,name会分配xw,当变量调用结束后,分配的内存地址也就消失
查看一个对象的数据类型,使用的关键字是type
python2:ascill
python3:unicode
编码:encode() 把字符串转为bytes数据类型的过程
解码:decode() 把bytes转为字符串的过程
str1=”xw”
print(str1,type(str1))
str_bytes=str1.encode(‘utf-8’)
print(str_bytes,type(str_bytes))
#解码
bytes_str=str_bytes.decode(‘utf-8’)
print(bytes_str,type(bytes_str))
import requests
r=requests.get(url=’https://www.gushiwen.cn/’)
print(r.content.decode(‘utf-8’))
#所有输入的都是字符串类型
#int()是把字符串强制的转为int的数据类型
while True:
score=int(input(‘输入学生成绩:\n’))
#print(‘学生成绩:\n’,score)
if score>=90 and score<100:
print(‘优秀‘)
elif score>=80 and score<90:
print(‘良好‘)
elif score>=60 and score<80:
print(‘及格‘)
elif score==100:
print(‘满分‘)
# continue继续:跳出本次循环
continue
else:
print(‘不及格‘)
#break:跳出整个循环
break
for循环
在数字右侧空白处左键可以标记代码进行打断点
输出方式
”’
%s:int 整型
%d:str 字符串
%f:float 数据类型
”’
name=’xw’
age=18
salary=123.321
print(‘我的名字:%s,我的年龄:%d,我的薪资:%f’%(name,age,salary))
print(‘我的名字:{0},我的年龄:{1},我的薪资:{2}’.format(name,age,salary))
print(‘我的名字:{name},我的年龄:{age},我的薪资:{salary}’.format(name=name,age=age,salary=salary))
#小写转大写upper
str1=’hello’
print(str1.upper())
#判断是否是大写
print(str1.upper().isupper())
#大写转小写 lower
str2=’HELLO’
print(str2.lower())
#判断是否是小写
print(str2.lower().islower())
str1=’hello’
#以什么开头satrtswith
print(str1.startswith(‘h’))
#以什么结尾endswith
print(str1.endswith(‘l’))
#获取字符串里面的元素索引:线性查找
print(str1.index(‘l’))
#获取字符串的长度len
print(len(str1))
#字符串的替换replace
print(str1.replace(‘ello’,’i,word’))
str1=’ hello ‘
#取消空格strip
print(str1.strip())
str2=’go,java,python’
#字符串的拆分,它的数据类型是列表,splist()中表示拆分的方法
str_list=str2.split(‘,’)
print(str_list,type(str_list))
list_str=’,’.join(str_list)
print(list_str,type(list_str))
str1=’hellp’
#返回的是索引,查找find
print(str1.find(‘l’))
#字符串的循环item
for item in str1:
print(item)
所谓列表,我们可以简单的把它理解为按照索引存放各种集合,在列表中,每个位置代表⼀个元素。在Python中,列表的对象⽅法是list类提供的,列表是有序的。列表的特点具体如下:
1. 可存放多个值
2. 按照从左到右的顺序定义列表元素,下标从0开始顺序访问
3. 列表是有序的
4. 列表也是可变化的,也就是说可以根据列表的索引位置来修改列表的值
list1=[“go”,”java”,”py”]
”’
append:默认吧添加的元素添加到最后一位
insert:按照索引添加
”’
list1.append(“c”)
print(list1)
list1.insert(0,”c+”)
print(list1)
#修改
list1[0]=’go语言‘
print(list1)
#循环
for item in list1:
print(item)
list1=[“go”,”java”,”py”]
#pop():删除最后一位并且返回结果
#remove:删除指定的任何一个元素
print(list1.pop())
print(list1)
list1.remove(‘java’)
print(list1)
#copy
#追加extend
#清空clear
list2=list1.copy()
print(list2)
list3=[1,2,3]
list1.extend(list3)
print(list1)
list1.clear()
print(list1)
list1=[“go”,”java”,”py”,”go”]
#元素在列表中的个数ocunt
#查看索引index
print(list1.count(‘go’))
print(list1.index(‘java’))
list1=[1,5,3,4,14,6,25]
#反转reverse()
#从小到大的排序sort
list1.reverse()
print(list1)
list1.sort()
print(list1)