Python Coding Flashcards
What type of language is python?
High-level programming language. Easy for humans to read, write and maintain but code is slower to run.
What is a statement?
Complete computer command.
What does an expression do?
Evaluates to the new value. e.g. 2*2
What does the function print() do?
Outputs and displays text in terminal.
What do variables do?
Stores values (not expressions) using assignment operator =. Variable names should describe stored data.
What are the different data types variables can store?
Int (whole no.), floats (decimal no.), strings (text)
What is the symbol and advantage of using multi-line strings?
”””
Anything between the “triple quotes” is part of the string including quotes, new lines and tab.
“””
What is a string concatenation?
Combing string values using the + symbol (joins w/o spaces).
What is the function of input()?
Assign user value as a variable. Prompt message printed beforehand.
What type of data is user input and what are some problems that may arise?
User input is entered as strings, therefore, calculations cannot be made. Must be converted to int.
What is the control flow and what does it allow us to do?
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.
What is a Boolean expression?
A statement that is true or false (whether or not it’s a fact).
What is an if statement used for?
Simple decisions.
What is an if-else statement used for?
Two-way decisions that describe what we want to happen if condition(s) are not met.
What is an if-elif-else statement used for?
Multi-way decisions that check for another condition after the statement.
What is a for loop used for and how do you write it?
Iterating a sequence; counting loops.
for (variable name) in range():
What is the break statement?
Used to leave loops early and jump to the next line of code outside the loop.
What is a library/module and how do you implement it into your code?
Built-in/pre-written functions to use in programs, called upon by “import”.
What is a library/module and how do you implement it into your code?
Built-in/pre-written functions to use in programs, called upon by “import”.
How to convert between different data types e.g. strings to numbers and numbers to strings?
int() or str()
What are lists, how do you write them and how are they different from strings?
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.
What is a method in Python listing and how would you write it?
Built-in functionality to create, manipulate or delete data. Listname.method()
What does the append method do?
Add an element onto the end of the list.
What is an index in a list and how do you write it?
The location of an element in a list. Python is zero-indexed. List.name[]. The negative index is the last element on the list.
How to change a value in a list?