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)

1
Q

What does the print() function do in Python?

A

It shows a message or output on the screen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are two things a function can do?

A

Make something happen. 2) Return a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three types of functions in Python?

A

1) Built-in functions
2) Functions from modules
3) Functions you create yourself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or False — A Python function can take any number of arguments, including none.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Besides the name, what else is important in a function?

A

The arguments — they’re the inputs the function uses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What should you think about when naming a function?

A

The name should describe what the function does.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do Python functions always need?

A

Parentheses () — even if there are no arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you run a function with arguments?

A

Put the arguments inside the parentheses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False — You must use parentheses even if there are no arguments.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a string?

A

A string is delimited with quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False: Anything you put in quotes will be taken literally, not as code but as data

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the steps of how a function is executed?

A
  1. Python checks if the specified name is legal.
  2. Python checks if the functions requirements for the number of arguments allows you to invoke the function in this way
  3. 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.
  4. The function executes its code, causes the desired effect (if any), evaluates the desired results (if any) and finishes the task.
  5. Python returns to your code (to the place just after the invocation) and resumes its execution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the print() function do?

A
  1. Takes in your message
  2. Converts it to something readable (if needed)
  3. Sends it to the screen

Whatever you put in print() shows up in the console.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What kind of arguments can you put in print()?

A

Anything

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does print() return?

A

Nothing (None). It just shows stuff—no value is given back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s unique about Python’s syntax?

A

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.

13
Q

How can you make a new line in Python?

A
  1. Use print()
  2. Use \n (newline character)
14
Q

What’s a backslash in a string called?

A

An escape character – it gives special meaning to the next letter.

15
Q

What does \n mean?

A

It means newline – it moves the output to the next line.