Week 0 Functions, Variables Flashcards
What are functions?
Functions are actions that the computer will already know how to perform. Ex: The computer already knows that when you’re using python, the print function means it needs to print something to the console.
How do you call a function?
You type the name of the function followed by parentheses () and if it takes an arguments, those go within the parentheses separated by commas
function(argument, argument)
How do you make your own function?
You can define a custom function using the keyword “def” followed by the function name and parentheses, then a colon. After the colon, you tab and each indented line following the colon is the definition or instructions of the new function. Then you can call the function and use it
What are variables
A variable is a container used to store data values in a program.
How do we use variables
Variables have names to identify them and values are assigned to variables using the = operator.
What are parameters?
A parameter is a placeholder used to represent a value in the parentheses following a function.
How do parameters work?
When you define a function, you specify parameters to indicate what kind of input it needs. When you call the function, you provide actual values for these parameters. This makes functions flexible and reusable because you can call them with different values.
Example:
Here’s a simple function with parameters in Python:
def greet(name):
print(“Hello, “ + name + “!”)
In this example:
name is a parameter. It’s a placeholder for the value you will pass when you call the greet function.
When you call the function, you provide an actual value (argument) for the parameter:
greet(“Alice”)
This call will output:
Hello, Alice!
What are conventions
Conventions are practices in programming languages that are important to follow but not technically necessary like syntax. They’re sort of like etiquette, a set of rules and standard practices that help to produce clean, readable code. Different languages have different conventions.
What are arguments?
Arguments are the actual values you pass to a function when you call it. These are the things parameters are placeholders for.
How do arguments work?
Here’s a simple function with an argument:
def greet(name):
print(“Hello, “ + name + “!”)
In this example:
name is a parameter in the function definition. It acts as a placeholder.
When you call the function, you provide an argument, which is the actual value for the parameter.
greet(“Alice”)
This call will output:
Hello, Alice!
What are side effects?
“side effects” refer to any situation where a function does something other than simply returning a value, such as printing to the console, altering data structures, modifying variables, or changing the state of the program in any way.
What is the point of main functions?
A main function is like a starting point of your program. You define a main function towards the top of the document with the other functions. Your main programming will be the definition of this function. Then you can call the main function to execute the code. This is useful for organizing code and is also useful if you’re important code as a module because you can use an if name statement to prevent the code from running automatically.
What are the most common types of interfaces?
Command-line interface (CLI), Graphical user interface (GUI), Menu driven interface, Question-and-answer interface
What are the pros and cons of the different interfaces
What is documentation?
How do you read documentation?
Why is it important to understand documentation
How do quotations work in python?
How do you use special formatting or f strings?
What are uses for special formatting
What are bugs
What is debugging
How does debugging work