PCEP Module 2: Introduction to Python and Computer Programming Flashcards
the fundamentals of computer programming, i.e., how the computer works, how the program is executed, how the programming language is defined and constructed; the difference between compilation and interpretation; what Python is, how it is positioned among other programming languages, and what distinguishes the different versions of Python. (20 cards)
What does the print() function do in Python?
It shows a message or output on the screen.
What are two things a function can do?
Make something happen. 2) Return a value.
What are the three types of functions in Python?
1) Built-in functions
2) Functions from modules
3) Functions you create yourself
True or False — A Python function can take any number of arguments, including none.
True
Besides the name, what else is important in a function?
The arguments — they’re the inputs the function uses.
What should you think about when naming a function?
The name should describe what the function does.
What do Python functions always need?
Parentheses () — even if there are no arguments.
How do you run a function with arguments?
Put the arguments inside the parentheses.
True or False — You must use parentheses even if there are no arguments.
True
What is a string?
A string is delimited with quotes.
True or False: Anything you put in quotes will be taken literally, not as code but as data
True
What are the steps of how a function is executed?
- Python checks if the specified name is legal.
- Python checks if the functions requirements for the number of arguments allows you to invoke the function in this way
- Python leaves your code for a moment and jumps into the function you want to invoke; of course, it takes your arguments too and passes it/them to the function.
- The function executes its code, causes the desired effect (if any), evaluates the desired results (if any) and finishes the task.
- Python returns to your code (to the place just after the invocation) and resumes its execution.
What does the print() function do?
- Takes in your message
- Converts it to something readable (if needed)
- Sends it to the screen
Whatever you put in print() shows up in the console.
What kind of arguments can you put in print()?
Anything
What does print() return?
Nothing (None). It just shows stuff—no value is given back.
What’s unique about Python’s syntax?
Normally, only one instruction per line is allowed.
You can split a long instruction across lines, but not stack multiple ones in a line without a semicolon.
How can you make a new line in Python?
- Use print()
- Use \n (newline character)
What’s a backslash in a string called?
An escape character – it gives special meaning to the next letter.
What does \n mean?
It means newline – it moves the output to the next line.