Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Default parameter

 
function addNum(a=0, b=0) {
    return a + b ;
}
 
 
console.log(addNum());              //1
console.log(addNum(1));             //1
console.log(addNum(1,2));           //3
 
Comment

Default argument values

def ask_ok(prompt, retries=4, reminder='Please try again!'):
    while True:
        ok = input(prompt)
        if ok in ('y', 'ye', 'yes'):
            return True
        if ok in ('n', 'no', 'nop', 'nope'):
            return False
        retries = retries - 1
        if retries < 0:
            raise ValueError('invalid user response')
        print(reminder)
Comment

default arguments

def get_student(name, grade='Five', age):
    print(name, age, grade)

# output: SyntaxError: non-default argument follows default argument
Comment

default arguments

def get_student(name, grade='Five', age):
    print(name, age, grade)

# output: SyntaxError: non-default argument follows default argument
Comment

PREVIOUS NEXT
Code Example
Python :: how to do square roots in python 
Python :: rename a column 
Python :: python object has no attribute 
Python :: rotate list python 
Python :: how to randomise a string in python 
Python :: numpy shuffle along axis 
Python :: how to get user input in python 
Python :: print list vertically python 
Python :: pandas add time to datetime 
Python :: pandas sort values in groupby 
Python :: change value in dataframe 
Python :: python string: .find() 
Python :: remove list of value from list python 
Python :: draw canvas in python 
Python :: Python communication with serial port 
Python :: how to extract digits from a string in python 
Python :: flask app.route 
Python :: games made with python 
Python :: corpus 
Python :: sequence in python 
Python :: import libraries to Jupyter notebook 
Python :: how to work with django ornm __in 
Python :: mapping in python 
Python :: miles to km in python 
Python :: reading an image using opencv library 
Python :: abstract class in python 
Python :: tkinter filedialog filename 
Python :: casefold in python 
Python :: função find python 
Python :: install multiple versions of python 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =