码迷,mamicode.com
首页 > 编程语言 > 详细

python函数入门

时间:2017-05-25 11:38:28      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:函数   结果   分数   one   基本功   数字   简洁   返回   str   

x=print(‘a‘)#返回a

print(a)  #返回None

下面介绍三种分数的程序员

a=[1,2,3,4]  #想让输出结果显示次数和数字一样(按总分五分来比较)

显示结果为:  

1

22

333

4444

第一种方法:  (三分)                               第二种方法: (四分)                                       第三种方法:(五分)

for x in a:                                               for  x in a:                                                        for x in  a:

    if x==1:                                                  if x==1:                                                           print(shr(x)*x)

       print(x)                                                 print(‘1‘)

    elif x==2:                                                if x==2:                                       当需求变更为(a=[1,2,3,4,5,6,7,8]),第一种必须改改能实现基本功能, 显然比较麻烦

       print(str(x)*2)                                     print(‘22‘)                                                                                         第二种也需要增加,简捷方便一点

    else:                                                        if x==3:                                                                                              第三种则不需要改变,最简洁省事

       if x==3:                                                   print(‘333‘)                                                                                        

          print(str(x)*3)                               if x=4:

       else:                                                         print(‘4444‘)

          print(str(x)*4)

python函数入门

标签:函数   结果   分数   one   基本功   数字   简洁   返回   str   

原文地址:http://www.cnblogs.com/Lyue/p/6902504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!