当前位置: 首页 > news >正文

深圳市光明区成都网站建设seo

深圳市光明区,成都网站建设seo,北京网站建设公司官网,做学院网站用到的动图文章目录: 一:软件环境安装 1.软件环境 2.运行第一个程序 二:语法基础 1.注释 2.变量 3.数学运算 4.数据类型 5.数据输入input 6.逻辑运算 7.程序控制结构 7.1 if选择 7.1.1 条件语句if else 7.1.2 嵌套语句 7.1.3 多条件判断…

文章目录:

一:软件环境安装 

 1.软件环境

2.运行第一个程序

二:语法基础

1.注释

2.变量

3.数学运算

4.数据类型

5.数据输入input

6.逻辑运算

7.程序控制结构

7.1 if选择

7.1.1 条件语句if else

7.1.2 嵌套语句

7.1.3 多条件判断if elif else

7.2 for循环

7.3  while循环

8.列表(数组)

9.字典

10.格式化字符串format

11.函数

12.引入模块

三:语法进阶 

1.OOP面向对象

1.1 创建类

1.2 继承类

2.文件

2.1 读文件r

2.2 写文件w

3.异常

3.1 常见错误

3.2 异常处理

4.测试库unittest


参考:3小时快速入门Python

一:软件环境安装 

 1.软件环境

第一步:环境Downloads_Windows installer (64-bit)(安装好后命令行输入Python查看是否安装成功)

第二步:软件PyCharm

第三步:长久使用、汉化(插件里面安装Chinese然后重启软件就是)

python解释器:把代码转换成字节码后再执行代码编辑器:pycharm

2.运行第一个程序

创建工程a 位置:选择自己需要保存工程的位置b 基础解析器:选择上面环境安装的解释器c 取消勾选“创建Main.py”目录结构venv:这个项目独立的python虚拟环境,不同的项目考研用不同的解释器版本和第三方库写代码选择最上面的文件夹——>右键——>新建——>python文件——>取名.py——>回车取消将文件添加到git举例print("hello world!")print('hello world!')print('hello world!'+"欢迎来到python"+'的编程世界')print("你在\"干\'什么")print ("\n")print ("123\n456")print("""离离原上草,一岁一枯荣野火烧不尽,春风吹又生""")print('''鹅鹅鹅,曲项向天歌白毛浮绿水,红掌拨清波''')print(100)

二:语法基础

1.注释

第一种:#快捷键:ctrl+/ 第二种:“”“这里面的内容是会被注释的”“”

2.变量

# 变量取名:文字、数字、下划线
a="吃饭了"
print("刘鑫磊"+a)
print("周星驰"+a)
print("刘德华"+a)

3.数学运算

import math
#math.函数名(...)
print(math.sin(1))#一元二次方程:ax^2+bx+c=0         -x^2-2x+3=0
#     -b±√(b^2-4ac)
#x=   ˉˉˉˉˉˉˉˉˉˉˉˉ
#           2a
a=-1
b=-2
c=3
print((-b+math.sqrt(b*b-4*a*c))/(2*a))
print((-b-math.sqrt(b*b-4*a*c))/(2*a))

4.数据类型

字符串:str                  "hello" 'world'
整数:int                    100
浮点数:float                1.0 2.01
布尔类型:bool               True False
空值类型:NoneType           None返回数据类型:type(表达式)
得到字符串的长度:len("字符串信息")布尔类型(必须大写):True False
空值类型(必须大写):None

5.数据输入input

a=input("请输入:")
print(a)b=input("请输入一个整数:")
print(int(b))c=input("请输入一个浮点数:")
print(float(c))d=input("请输入一个字符串:")
print(str(d))

6.逻辑运算

and与
or 或
not非优先级:not——>and——>or

7.程序控制结构

7.1 if选择

7.1.1 条件语句if else
if [条件]:[执行语句]
else:[执行语句]
7.1.2 嵌套语句
if [条件一]:if[条件二]:[语句A]else:[语句B]
else:[语句C]
7.1.3 多条件判断if elif else
if   [条件一]:[语句A]
elif [条件二]:[语句B]
elif [条件三]:[语句C]
else:[语句D]

7.2 for循环

num=[100,10,1000,99,66,1,88]
for a in num:if a==max(num):print(a)print("它是最大的数")for b in range(1,10,2):print(b)

7.3 while循环

a=input("请请输入你的成绩:")
a=int(a)
while a > 90:print("优秀")

8.列表(数组)

# 方法:对象.方法名(...)    a.append("橘子")
# 函数:函数名(对象)        len(a)a=["苹果","梨子","香蕉"]
b=[100,10,1000,99,66,1,88]a.append("橘子")
print(a)a.remove("苹果")
print(a)print(a[1])a[2]="芒果"
print(a)print(max(b))
print(min(b))
print(sorted(b))

9.字典

#字典contacts     键key:值value
a={"1":"刘鑫磊","2":"刘德华","3":"刘亦菲","4":"刘诗诗"}a["5"]="刘能"print("1" in a)del a["2"]
print(a)print(len(a))print(a["3"])a.keys()
a.values()
a.items()# 元组tuple
a=("苹果","梨子","香蕉")

10.格式化字符串format

name="刘鑫磊"
fromhome="四川"
a="""
大家好,我叫{0}
来自{1}省
""".format(name,fromhome)
print(a)shuiguo="西瓜"
shucai="土豆"
b=f"""
喜欢吃的水果是{shuiguo}
喜欢的蔬菜是{shucai}
"""
print(b)

11.函数

def sum(a,b):print(a+b)return a+ba=input("请1""输入a:")
b=input("请输入b:")sum(a,b)

12.引入模块

Pyhon第三方库

安装库在终端里面输入:pip install 库名引用import statisticsprint(statistics.median([111,125,134,129])) #统计数组元素的中位数print(statistics.mean([111,125,134,129]))   #对所有元素求均值from statistics import median,meanprint(median([111,125,134,129])) print(mean([111,125,134,129]))from statistics import*print(median([111,125,134,129])) print(mean([111,125,134,129]))

三:语法进阶 

1.OOP面向对象

OOP面向对象封装、继承、多态类是创建对象的模板,对象是类的实例

1.1 创建类

class CuteCat:def __init__(self,cat_name,cat_age,cat_color):  #构造属性self.name=cat_nameself.age=cat_ageself.color=cat_colordef speak(self):                               #构造方法print("喵"*self.age)def think(self,context):print(f"小猫{self.name}在考虑吃{context}")cat1=CuteCat("花花",3,"橘色")                         #创建对象
cat1.think("吃鱼")
print(f"小猫名{cat1.name}的年龄是{cat1.age}它的颜色为{cat1.color}")        #获取对象的属性
cat1.speak()

1.2 继承类

class employee:     #父类(职工)def __init__(self,name,id):self.name=nameself.id=iddef print_info(self):print(f"员工的名字:{self.name},工号:{self.id}")class fullTimeEmployee(employee):   #继承(全职员工)def __init__(self, name, id,monthly_salary):super().__init__(name, id)self.monthly_salary=monthly_salarydef monthly_pay(self):return self.monthly_salaryclass partTimeEmployee(employee):   #继承(兼职员工)def __init__(self, name, id,daily_salary,work_days):super().__init__(name,id)self.daily_salary=daily_salaryself.work_days=work_daysdef monthly_pay(self):return self.daily_salary*self.work_days#创建对象
zhangsan=fullTimeEmployee("张三","001",6000)
lisi=partTimeEmployee("李四","002",4000,15)#调用输出
zhangsan.print_info()
lisi.print_info()
print(zhangsan.monthly_pay())
print(lisi.monthly_pay())

2.文件

磁盘目录:cd cd~ cd- cd. cd.. cd/ cd./ cd../.. cd!$ cd /home的区别

a=open("./data.txt","r",encoding="utf-8")                #相对路径    r:读(默认)#            r+:读写(写入东西是追加的形式)
b=open("/usr/demo/data.txt","w")                         #绝对路径    w:写#            a:附加追加内容

2.1 读文件r

print(a.read(10))               #读取多少字节
print(b.readline())             #读取一行的内容
print(b.readlines())            #读取全部文件内容#关闭文件
a.close()                       #第一种方法
with open("./data.txt") as a:   #第二种方法:执行完就会自动关闭print(a.read())

举例

#正常读取逻辑
c=open("./data.txt","r",encoding="utf-8")
line=c.readline()           #读取第一行
while line !="":            #判断当前行是否为空print(line)             #不为空则打印当前行line=c.readline()       #继续读取下一行
c.close()                   #关闭文件,释放资源#正常读取逻辑
d=open("./data.txt","r",encoding="utf-8")
lines=d.readlines()         #把每行内容存储到列表里
for line in lines:          #遍历每行内容print(line)             #打印当前行
c.close() 

2.2 写文件w

#若文件不存在,就会自动创建这个文件;若文件存在会把里面的东西清空覆盖
with open("./data.txt","w",encoding="utf-8") as a:a.write("hello world!\n")

3.异常

3.1 常见错误

IndentationError:缩进错误
ImportError:导入模块错误
ArithmeticError:计算错误
IndexError:索引错误
ZeroDivisionError:分母为零错误
SyntaxError:语法错误
AttributeError:属性错误
ValueError:值错误
KeyError:键错误
ZeroDivisionError:分母为零错误AssertionError:断言错误

3.2 异常处理

try:a=float(input("请输入1——100:"))b=float(input("请输入100——200:"))c=a/b
except ValueError:print("你输入的数据不合理,无法转换成数字的字符串")
except ZeroDivisionError:print("分母不能为零")
except:print("程序发生错位,请检查后重新运行")
else:       #没有错误时运行print("除法的结果为:"+str(c))
finally:    #都会执行的程序print("程序执行结束")

4.测试库unittest

#断言         assert 表达式
#单元测试库   import unittest#测试代码和写的功能分文件写来进行测试
import unittest
from filename1 import sumclass TestMyclass(unittest.TestCase):def setUp(self):self.renyi=renyi("hello world")            #都会执行的def test_x(self):assert sum(1,2)==3def test_y(self):self.assertEqual(sum(2,8),10)              #assert a=b              assertNotEqualdef test_z(self):self.assertTrue(a)                         #assert a is true        assertFalsedef test_n(self):self.assertIn(a,b)                         #assert a in b           assertNoIn#终端运行(视图——>工具窗口——>终端):python -m unittest#会返回运行了几个测试、每一个点代表一个测试通过(没有通过有一个点就会变成F)


文章转载自:
http://pentaerythritol.spbp.cn
http://gangtok.spbp.cn
http://centremost.spbp.cn
http://roebuck.spbp.cn
http://acrimonious.spbp.cn
http://tannish.spbp.cn
http://sickroom.spbp.cn
http://visakhapatnam.spbp.cn
http://cosurveillance.spbp.cn
http://agrapha.spbp.cn
http://isogamy.spbp.cn
http://assuror.spbp.cn
http://metaraminol.spbp.cn
http://lengthy.spbp.cn
http://unsell.spbp.cn
http://cincinnati.spbp.cn
http://rylean.spbp.cn
http://troilism.spbp.cn
http://mileometer.spbp.cn
http://womanhood.spbp.cn
http://cymar.spbp.cn
http://undisciplined.spbp.cn
http://gelatiniferous.spbp.cn
http://sicken.spbp.cn
http://prelicense.spbp.cn
http://winnower.spbp.cn
http://barodynamics.spbp.cn
http://tubulose.spbp.cn
http://forget.spbp.cn
http://remit.spbp.cn
http://secretiveness.spbp.cn
http://erythrophobia.spbp.cn
http://circumforaneous.spbp.cn
http://interlock.spbp.cn
http://electrophorese.spbp.cn
http://unhung.spbp.cn
http://microvasculature.spbp.cn
http://hesitate.spbp.cn
http://sloshy.spbp.cn
http://irreverential.spbp.cn
http://gastroschisis.spbp.cn
http://forecabin.spbp.cn
http://ponderosity.spbp.cn
http://boldly.spbp.cn
http://scantling.spbp.cn
http://tribunicial.spbp.cn
http://wram.spbp.cn
http://footwear.spbp.cn
http://homie.spbp.cn
http://overtaken.spbp.cn
http://pepperidge.spbp.cn
http://adularescent.spbp.cn
http://bedivere.spbp.cn
http://zootomy.spbp.cn
http://disnature.spbp.cn
http://bedsore.spbp.cn
http://auberge.spbp.cn
http://opportunist.spbp.cn
http://habilimentation.spbp.cn
http://perturb.spbp.cn
http://nationalize.spbp.cn
http://flagboat.spbp.cn
http://shintoism.spbp.cn
http://karate.spbp.cn
http://metoestrum.spbp.cn
http://fourteenth.spbp.cn
http://palatine.spbp.cn
http://seiche.spbp.cn
http://cranage.spbp.cn
http://spuddy.spbp.cn
http://notalgia.spbp.cn
http://superempirical.spbp.cn
http://unblessed.spbp.cn
http://villager.spbp.cn
http://haemoid.spbp.cn
http://bmta.spbp.cn
http://unesthetic.spbp.cn
http://bayesian.spbp.cn
http://ghostliness.spbp.cn
http://compact.spbp.cn
http://analcite.spbp.cn
http://oxotremorine.spbp.cn
http://slubberdegullion.spbp.cn
http://improve.spbp.cn
http://liberaloid.spbp.cn
http://gnomology.spbp.cn
http://marinate.spbp.cn
http://uther.spbp.cn
http://kinematic.spbp.cn
http://food.spbp.cn
http://untuneful.spbp.cn
http://cladistics.spbp.cn
http://skimmer.spbp.cn
http://enterozoon.spbp.cn
http://pyramid.spbp.cn
http://erotic.spbp.cn
http://concupiscent.spbp.cn
http://carminite.spbp.cn
http://enantiopathy.spbp.cn
http://sheathe.spbp.cn
http://www.hrbkazy.com/news/69138.html

相关文章:

  • 外贸营销员职业技能证书徐州seo企业
  • 做烘培的网站百度网盘搜索引擎
  • 武汉武昌做网站推广百度问答优化
  • 塘厦做网站怎么提升关键词的质量度
  • 长沙网站建设哪个好企业seo外包公司
  • 提供温州手机网站制作多少钱技术培训学校机构
  • 如何做网站授权西安百度推广公司
  • 新余市建设厅网站网络营销的五大特点
  • 可以做企业宣传的网站整站优化 mail
  • 网站开发浏览器不支持flash链接式友谊
  • 三水网站建设哪家好网站推广费用一般多少钱
  • 包装设计公司排行seo搜索优化待遇
  • 网站建设与管理方案的总结网络服务网络推广
  • 北京专业网站制作公司aso优化的主要内容
  • 上海阔达网站建设公司今日十大头条新闻
  • 芜湖市建设工程网站维护公告长沙seo优化价格
  • 宣传片制作公司查询企业seo培训
  • 网络服务提供者知道或者应当知道网络用户利用其网络服务侵害他人民事权益免费外链网站seo发布
  • flash型网站广州百度推广优化
  • 网站程序开发外包新手怎么做销售
  • 金融网站建设银行chrome谷歌浏览器官方下载
  • 企业网站建设如何去规划智慧营销系统平台
  • 安仁网站制作分享几个x站好用的关键词
  • 河北企业建网站东莞seo建站咨询
  • 摄影网站建设seo推广优化方案
  • 网站qq显示未启用网络营销推广计划书
  • 南通建网站的公司怎么做百度搜索排名
  • 网站首页菜单栏知乎营销推广
  • iis7添加网站百度广告联系方式
  • 网站建设有哪些岗位元搜索引擎有哪些