Created
March 20, 2019 03:59
-
-
Save caoya171193579/12c506751e4093e605879352369a3260 to your computer and use it in GitHub Desktop.
未学习的内容,补上。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch(四维持): | |
switch 用于编写多分支结构的程序,类似于 (if... elif... else)语句。 | |
switch 语句表达的分支结构比(if... elif... else)语句表达的更清晰,代码的可读性更高。 | |
但是python并没有直接提供switch 语句。 | |
python 可以通过字典实现switch语句的功能。 | |
实现方法分为两步。 | |
-首先,定义一个字典。 | |
-其次,调用字典的get()获取相应的表达式。 | |
########################################## | |
在python下有些不能除尽的除法运算需要加小数点才能得到结果, 我们也可以使用调用模块 | |
from __future__ import division ,调用__future__(非有车儿)模块下的division(德伟什)参数, 所有的除法都能除尽了。 | |
 | |
实现,不用做(if... elif... else)判断的四则运算 | |
 | |
结果 | |
 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment