是否需要自己建设网站才能在京东开店?

摘要:入驻京东需要自己做网站吗,重庆森林在线观看,网上seo研究,小语种网站案例Python3 条件控制 Python 条件语句是通过一条或多条语句的执行结果(True 或者 False&#xff09
入驻京东需要自己做网站吗,重庆森林在线观看,网上seo研究,小语种网站案例Python3 条件控制 Python 条件语句是通过一条或多条语句的执行结果#xff08;True 或者 False#xff09;来决定执行的代码块。 可以通过下图来简单了解条件语句的执行过程: 代码执行过程#xff1a; if 语句 Python中if语句的一般形式如下所示#xff1a; if condi…Python3 条件控制 Python 条件语句是通过一条或多条语句的执行结果True 或者 False来决定执行的代码块。 可以通过下图来简单了解条件语句的执行过程: 代码执行过程 if 语句 Python中if语句的一般形式如下所示 if condition_1:statement_block_1 elif condition_2:statement_block_2 else:statement_block_3如果 “condition_1” 为 True 将执行 “statement_block_1” 块语句 如果 “condition_1” 为False将判断 “condition_2” 如果condition_2 为 True 将执行 “statement_block_2” 块语句 如果 “condition_2” 为False将执行statement_block_3块语句 Python 中用 elif 代替了 else if所以if语句的关键字为if – elif – else。 注意 1、每个条件后面要使用冒号 :表示接下来是满足条件后要执行的语句块。 2、使用缩进来划分语句块相同缩进数的语句在一起组成一个语句块。 3、在 Python 中没有 switch…case 语句但在 Python3.10 版本添加了 match…case功能也类似详见下文。 以下是一个简单的 if 实例 #!/usr/bin/python3var1 100 if var1:print (1 - if 表达式条件为 true)print (var1)var2 0 if var2:print (2 - if 表达式条件为 true)print (var2) print (Good bye!)执行以上代码输出结果为 1 - if 表达式条件为 true 100 Good bye!从结果可以看到由于变量 var2 为 0所以对应的 if 内的语句没有执行。 以下实例演示了狗的年龄计算判断 #!/usr/bin/python3age int(input(请输入你家狗狗的年龄: )) print() if age 0:print(你是在逗我吧!) elif age 1:print(相当于 14 岁的人。) elif age 2:print(相当于 22 岁的人。) elif age 2:human 22 (age -2)*5print(对应人类年龄: , human)### 退出提示 input(点击 enter 键退出)将以上脚本保存在dog.py文件中并执行该脚本 $ python3 dog.py 请输入你家狗狗的年龄: 1相当于 14 岁的人。 点击 enter 键退出以下为if中常用的操作运算符: #!/usr/bin/python3# 程序演示了 操作符 # 使用数字 print(5 6) # 使用变量 x 5 y 8 print(x y)以上实例输出结果 False Falsehigh_low.py文件演示了数字的比较运算 #!/usr/bin/python3 # 该实例演示了数字猜谜游戏 number 7 guess -1 print(数字猜谜游戏!) while guess ! number:guess int(input(请输入你猜的数字))if guess number:print(恭喜你猜对了)elif guess number:print(猜的数字小了...)elif guess number:print(猜的数字大了...)执行以上脚本实例输出结果如下 $ python3 high_low.py 数字猜谜游戏! 请输入你猜的数字1 猜的数字小了... 请输入你猜的数字9 猜的数字大了... 请输入你猜的数字7 恭喜你猜对了if 嵌套 在嵌套 if 语句中可以把 if…elif…else 结构放在另外一个 if…elif…else 结构中。 if 表达式1:语句if 表达式2:语句elif 表达式3:语句else:语句 elif 表达式4:语句 else:语句# !/usr/bin/python3numint(input(输入一个数字)) if num%20:if num%30:print (你输入的数字可以整除 2 和 3)else:print (你输入的数字可以整除 2但不能整除 3) else:if num%30:print (你输入的数字可以整除 3但不能整除 2)else:print (你输入的数字不能整除 2 和 3)将以上程序保存到 test_if.py 文件中执行后输出结果为 $ python3 test.py 输入一个数字6 你输入的数字可以整除 2 和 3match…case Python 3.10 增加了 match…case 的条件判断不需要再使用一连串的 if-else 来判断了。 match 后的对象会依次与 case 后的内容进行匹配如果匹配成功则执行匹配到的表达式否则直接跳过_ 可以匹配一切。 语法格式如下 match subject:case pattern_1:action_1case pattern_2:action_2case pattern_3:action_3case _:action_wildcardcase _: 类似于 C 和 Java 中的 default:当其他 case 都无法匹配时匹配这条保证永远会匹配成功。 mystatus400 print(http_error(400))def http_error(status):match status:case 400:return Bad requestcase 404:return Not foundcase 418:return Im a teapotcase _:return Somethings wrong with the internet以上是一个输出 HTTP 状态码的实例输出结果为 Bad request一个 case 也可以设置多个匹配条件条件使用 隔开例如 ...case 401|403|404:return Not allowed