FlashKeepers

Python · Python · College and University

Python Basics: Functions and Control Flow

Python function definitions, loops, and conditional logic explained with a short example each.

About this set

40 basic cards for Python Python. Set 1 of 2 in Python Basics. It opens with "How do you define a function in Python?" and "What does a function parameter do?". More College and University decks are listed below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

How do you define a function in Python?
Show answerUse def, the function name, parentheses, a colon, then indent the body.
What does a function parameter do?
Show answerA parameter is a named placeholder for a value passed when the function is called.
How do you return a value from a function?
Show answerUse the return keyword followed by the value to send back to the caller.
What is a default parameter?
Show answerA parameter with a preset value used when no argument is passed for that parameter.
Give an example of a function with two parameters
Show answerdef add(a, b): return a + b
What happens if a function has no return statement?
Show answerThe function returns None implicitly.
What is a function docstring?
Show answerA string literal placed right after the def line to document what the function does.
How do you call a function named greet?
Show answerWrite the function name followed by parentheses: greet()
What are positional arguments?
Show answerArguments passed to a function in the order they appear in the definition.
How do you pass keyword arguments to a function?
Show answerUse the parameter name followed by an equals sign and the value: func(name='Alice')
What does *args allow you to do?
Show answerPass a variable number of positional arguments to a function.
What does **kwargs allow you to do?
Show answerPass a variable number of keyword arguments to a function.
What is the basic structure of an if statement?
Show answerif condition: followed by indented code that runs only if condition is true
What is the structure of an if-else statement?
Show answerif condition: runs if true, else: runs if condition is false
How do you add a third branch to a conditional?
Show answerUse elif (else if) for additional conditions between if and else.

25 more cards in the app

Study this set free