首页 > 代码库 > python函数入门

python函数入门

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函数入门