Python从入门到网络爬虫、自动化

可以创建C++、C#、Python、Golang、Java、React、Node、Vue、PHP项目

创建Java项目

创建Python项目

简单if......else......语句

python 复制代码
# 简单的if......else......语句
state = True
if state:
    print("状态正常")
else:
    print("状态异常")

# 复杂的if......elif......语句
score = 88
def __getlevel__(score):
    level = ""
    if score >= 85 and score <=100:
        level = "A"
    elif score >=70 and score < 85:
        level = "B"
    elif score >=60 and score < 70:
        level = "C"
    elif score < 60:
        level = "D"
    return level
level = __getlevel__(score)
print("my level is :"+level)

# 嵌套if语句

Python从入门到精通

python 复制代码
'''
  条件语句
'''
# 普通if......else......语句
# 定义变量 存放状态
state = True


# 定义函数 计算状态
def getState(state):
  if state:
    print("状态启用")
  else:
    print("状态关闭")


# 调用函数 打印状态
getState(state)

# if......elif......语句
# 定义变量 存放得分
scored = 78


# 定义函数 计算等级
def getLevel(scored):
  # if else条件语句
  if scored >= 85 and scored <= 100:
    print("A")
  elif scored >= 70 and scored <= 84:
    print("B")
  elif scored >= 60 and scored <= 69:
    print("C")
  else:
    print("D")


# 调用函数 打印等级
getLevel(scored)

# if......else语句嵌套

# while循环语句
j = 1
# 简单while循环语句
while j < 10:
  print(j)
  j += 1

# while语句中使用 break、continue跳出循环
# while循环中使用break语句用于跳出整个循环
x = 0
while x < 10:
  x += 1
  if x % 2 == 0:
    break
  print("x:" + str(x))
# 输出 x:1

# while循环中continue语句用于跳出本次循环
while x < 10:
  x += 1
  if x % 2 == 0:
    continue
  print("x:" + str(x))
# 输出 x:1 x:3 x:5 x:7 x:9

# while......else......语句

# for循环语句
for i in range(1, 10):
  print("for:" + str(i))
# 循环字符串
for i in "python":
  print(i)
# 循环元组

# for......else......语句
for i in range(1,10):
  print(i)


# pass语句就是
if state:
  print("True")
else:
  pass
  print("False")
相关推荐
IT小哥哥呀39 分钟前
Nginx高可用配置实战:负载均衡 + 健康检查 + 动态扩展
运维·nginx·负载均衡·devops·日志分析·openresty·动态扩展
刘某的Cloud1 小时前
ceph osd down排查
linux·运维·ceph·系统·osd
喜欢你,还有大家5 小时前
Docker-仓库-镜像制作
运维·docker·容器
LabVIEW开发6 小时前
LabVIEW是否适合商业化软件开发
自动化·labview
安审若无6 小时前
图数据库neoj4安装部署使用
linux·运维·数据库
做运维的阿瑞6 小时前
CentOS DNS故障排查完整解决方案:从症状到根因的系统化诊断
linux·运维·centos
深圳市恒讯科技7 小时前
英国服务器Windows系统远程桌面安装与优化
运维·服务器·windows
itachi-uchiha7 小时前
head和tail命令使用
linux·运维·服务器
violet-lz7 小时前
Socket编程实战:从基础API到多线程服务器
运维·服务器
初学者_xuan7 小时前
零基础新手小白快速了解掌握服务集群与自动化运维(十六)集群部署模块——LVS-DR&TUN模式配置
运维·自动化·lvs