Python Coding Flashcards

1
Q

What type of language is python?

A

High-level programming language. Easy for humans to read, write and maintain but code is slower to run.

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

What is a statement?

A

Complete computer command.

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

What does an expression do?

A

Evaluates to the new value. e.g. 2*2

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

What does the function print() do?

A

Outputs and displays text in terminal.

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

What do variables do?

A

Stores values (not expressions) using assignment operator =. Variable names should describe stored data.

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

What are the different data types variables can store?

A

Int (whole no.), floats (decimal no.), strings (text)

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

What is the symbol and advantage of using multi-line strings?

A

”””
Anything between the “triple quotes” is part of the string including quotes, new lines and tab.
“””

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

What is a string concatenation?

A

Combing string values using the + symbol (joins w/o spaces).

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

What is the function of input()?

A

Assign user value as a variable. Prompt message printed beforehand.

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

What type of data is user input and what are some problems that may arise?

A

User input is entered as strings, therefore, calculations cannot be made. Must be converted to int.

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

What is the control flow and what does it allow us to do?

A

The sequence in which a program’s code is executed is regulated by conditional statements, functions and loops. Allows alternative courses of action to be taken depending on the occurrence of an event.

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

What is a Boolean expression?

A

A statement that is true or false (whether or not it’s a fact).

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

What is an if statement used for?

A

Simple decisions.

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

What is an if-else statement used for?

A

Two-way decisions that describe what we want to happen if condition(s) are not met.

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

What is an if-elif-else statement used for?

A

Multi-way decisions that check for another condition after the statement.

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

What is a for loop used for and how do you write it?

A

Iterating a sequence; counting loops.
for (variable name) in range():

17
Q

What is the break statement?

A

Used to leave loops early and jump to the next line of code outside the loop.

18
Q

What is a library/module and how do you implement it into your code?

A

Built-in/pre-written functions to use in programs, called upon by “import”.

18
Q

What is a library/module and how do you implement it into your code?

A

Built-in/pre-written functions to use in programs, called upon by “import”.

19
Q

How to convert between different data types e.g. strings to numbers and numbers to strings?

A

int() or str()

20
Q

What are lists, how do you write them and how are they different from strings?

A

A collection of data (strings, numbers or a mixture of both) in sequential order. Variable.name = [] (square brackets). They are mutable (changeable values) and can remain empty.

21
Q

What is a method in Python listing and how would you write it?

A

Built-in functionality to create, manipulate or delete data. Listname.method()

22
Q

What does the append method do?

A

Add an element onto the end of the list.

23
Q

What is an index in a list and how do you write it?

A

The location of an element in a list. Python is zero-indexed. List.name[]. The negative index is the last element on the list.

24
Q

How to change a value in a list?

A