python 中有取代if-if elif else-else 的东西吗

君,已阅读到文档的结尾了呢~~
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
Python-if-elif-else语句
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
中有取代if-elif-else的东西吗要是这样的呢:
if y == 'a':
if x & =10:
a = function(1)
elif x & 10 and x &= 30:
a =function(2)
a = function(3)
elif y =='b':
if x & =11:
a = function(2)
elif x & 11 and x &= 30:
a =function(3)
a = function(4)
elif y == 'c':
if x & =30:
a = function(3)
a = function(4)
return false
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
d = {'a':function(1),'b':function(2),'c':function(3)}
a = x &= 10 and 'a' or (10 & x &=30 and 'b' or 'c')
手机写代码简直痛不欲生。。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
存在即合理。正常情况下,集中条件判断都很好换着写同样的功能。不过,if-elif-else的阅读性真的很好。至于效率的话,等你涉及到时间复杂度及算法优化等性能问题时,你就会发现很多优秀的算法中,也会用if-elif-else。
分享到微博?
你好!看起来你挺喜欢这个内容,但是你还没有注册帐号。 当你创建了帐号,我们能准确地追踪你关注的问题,在有新答案或内容的时候收到网页和邮件通知。还能直接向作者咨询更多细节。如果上面的内容有帮助,记得点赞 (????)? 表示感谢。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
扫扫下载 AppPython-if-elif-else语句
#!/bin/env python
# coding=gb2312
# -*- coding: gb2312 -*-
from __future__ import division
#### if-else ####
print '#### if-else ####'
a = input(&a: &) # 12 or 10+2
b = input(&b: &)
print &max: &, a
print &max: &, b
#### if-elif-else ####
print '#### if-elif-else ####'
score = raw_input(&score: &) # string
score = int(score)
if(score&=90) and (score&=100):
elif(score&=80 and score&90):
elif(score&=60 and score&80):
#### switch I ####
print '#### switch ####'
operator = &/&
result = {
print result.get(operator)
#### switch II ####
print '#### switch II ####'
class switch(object):
def __init__(self, value):
# init value
self.value = value
self.fall = False
# no break, then fall=False
def __iter__(self):
yield self.match
# match method to create
raise StopIteration
# exception to check loop
def match(self, *args):
if self.fall or not args:
return True
elif self.value in args: # successful
self.fall = True
return True
return False
operator = &+&
for case in switch(operator):
if case('+'):
if case('-'):
if case('*'):
if case('/'):
if case():
print 'NULL'
[work@db-testing-com06-vm3. python]$ python if_else.py&
#### if-else ####
#### if-elif-else ####
#### switch ####
#### switch II ####
================================================================
中文注释参考:
一个极小的问题。在python代码中,用了中文注释,不能被python解释器理解(python 2.5)。解决方案是:
#&coding=gb2312
print&'ok'&#中文注释没问题
#&-*-&coding:&gb2312&-*-
print&'ok'&&#这样也行
代码详解参考:
原文链接:

我要回帖

更多关于 shell if elif else 的文章

 

随机推荐