zoukankan      html  css  js  c++  java
  • Python和java 的区别笔记(未完成)

    1.  非  boolean not

    Python     not 

    java           !

     2.函数中的缺省值

    如果函数中有一个值是 常用的例如下图的 score  合格分数线

    def  overScoreStudents(studentScoreList, score):
        count = 0
    
        # 下面的代码用到了循环和判断,后面章节会学习到
        for ss in studentScoreList:
            if ss >= score:
                count += 1
        
        return count

    那么可以写为

    def  overScoreStudents(studentScoreList, score=60):

    那么 如果没有定于score时 ,直接  overScoreStudents(ssList)  此时score默认为60

    如果需要定义时 overScoreStudents(ssList, 70) 此时score为70

    注意:arg4 前面的参数 arg3 已经有缺省值,所以必须也要有缺省值,比如

    def  func(arg1, arg2, arg3=3, arg4='hello'):

    指定参数名调用函数

    这样的一个函数

    def  func(arg1, arg2, arg3=3, arg4='hello'):
        print(arg1)
        print(arg2)
        print(arg3)
        print(arg4)
    

    我们调用的时候,可以这样

    func(1,2,3,'hello')

    也可以这样 指定参数名 去调用

    func(arg1=1,arg2=2,arg3=3,arg4='hello')

    指定参数名调用的时候,可以颠倒参数的次序

    func(arg2=1,arg3=2,arg1=3,arg4='hello')

    也可以这样混合使用

    func( 1, 2, arg3=3,arg4='hello')
    


    但是一旦某个参数指定了参数名,后面所有的参数必须指定参数名

    像下面这样是不可以的

    func( 1, 2, arg3=3, 'hello') # 错误的调用方式
  • 相关阅读:
    Reactivecocoa初级使用
    javascript中typeof用法
    javascript进阶修炼之二——DOM,事件及定时器
    javascript进阶修炼之一——javascript必备操做
    HttpClient通信
    JSON和JSONP简单总结
    cordova学习-基础篇
    浅析Java虚拟机结构与机制
    HTML5移动Web开发指南-学习笔记(一)
    spring beans 源码解读
  • 原文地址:https://www.cnblogs.com/goodgoodstudy2018/p/13947673.html
Copyright © 2011-2022 走看看