MSCDSA01 - Foundation Flashcards
Foundational Data Science - Inc lots of Python
What is Tkinter and what is it used for?
A python module, for building a graphical interface
What is SQLite and what is it used for?
(an alternative to writing to a text file)
What is ‘pdb’ and what is it used for?
which can be used to find elusive logic errors
What are the string type identifiers in Python?
you can use single or double quotes, either is fine - ‘ or “
what does the ‘' character inside a string do?
The \ tells python to expect a number or character afterwards which will indicate printing a special character \ = newline \\ = \ \' = ' \" = " \a = ASCII Bell(BEL) \b = ASCII Backspace (BS) \f = ASCII Formfeed (FF) \n = ASCII Linefeed (LF)(newline) ..etc
How do you ‘print’ to the console in python?
print ( )
eg:
print (‘Hello World’)
——
or print ("Hello World") but NOT Print ('Hello World') = capital Would not be recognised (case sensitive) and whitespace means something and is not ignored)
What is ‘Spyder’ and what is it used for?
Spyder is an open source integrated development environment (IDE) for scientific programming in the Python language
What does ‘Syntax’ mean in programming?
the rules (like grammar in written language) define combinations of symbols to make a correctly structured expression. --------
Applies both for programming languages, (source code), and for markup languages, where the document represents data.
What is a ‘markup language’?
from the “marking up” of paper manuscripts; replaced digitally by tags, indicating what the elements of text ARE, rather than how they might be shown on a display
Is python a ‘compiled’ or an ‘interpreted’ language, and what is the difference?
It has elements of a ‘compiled’ language, having compilers available
What are the two modes of entering and running programs in Python?
Interactive mode = type instructions and python responds immediately
Script mode = type in and SAVE
In ‘Jupyter’ what is the key combination to run a python program?
alt+enter or ctrl+enter or cmd+enter
In language theory and programming what is the term for joining character strings end-to-end?
For example, the concatenation of “snow” and “ball” is “snowball”
How would you put single or double quotes inside a string in python?
eg if you want a “ inside the string, then encapsulate (define) the string using the ‘ (single quote) character
What symbol is used to concatenate strings in Python
+
so “A” + “B” would produce AB
What are the the numeric data types in python?
int = integer (a whole number) float = floating point (a number with a decimal point)
what are the standard arithmetic operators in python?
\+, -, * (multiply) and / (divide) ** for exponentiation (eg 2 ** 3 = 8 = 2^3) % (mod) returns the remainder when an integer is divided by another (11 % 5 = 1) // (div) performs integer division (11 // 5 = 2)
In python when does numerical division result in a floating point number?
use ‘//’ to get an integer without remainder or decimal
In python which is the divide symbol ‘ \ ‘ or ‘ / ‘
remember your Christmas tree, it was the right hand slope ‘ \ ‘ that gave the problem because its an escape sequence and you needed ‘\' to get \
In Python why does 1.62+0.53 = 2.1500000000000004 how to avoid it?
To be certain of out put use the round() function:
round(1.62+0.53,2)
What is the TRUE/FALSE data type called?
Boolean
What are the true false answers to the following: 9 == 3*3 9 != 3*3 9 == 4*4 9 != 4*4 (5 > 1) and (7 > 1) (1 > 5) and (7 > 1) (1 > 5) or (7 > 1)
TRUE FALSE FALSE TRUE TRUE FALSE TRUE
In Python what would the following evaluate to:
9 != 4*4
TRUE
In Python what would the following evaluate to:
1 > 5) and (7 > 1
FALSE
In Python what are the 3 standard convention for naming variables?
1) make the names meaningful.
2) start with a lower case letter
3) use “camel caps” to separate parts of a name
eg. highScore
In Python what is the standard convention for naming constants?
1) make the name meaningful.
2) use ALLCAPS
eg. VATRATE
What is an assignment operator in Python?
It is how you assign a value to an object, e.g .
This is done using the ‘=’ operator.
length = 4 means the variable name (left) has the value (right) assigned to it
In python what is an ‘augmented assignment operator’
A way to update a variable e.g.
score +=1
is equivalent to
You can NOT use one if the variable has not yet been defined
what do the following ‘augmented assignment operators’ do?
A) +=
B) -=
C) *=
D) /=
E) %=
F) //=
variableA ‘+=’ rhValue
A) add the right hand value or variable to variableA
B) subtract the right hand value or variable from variableA
C) multiply variableA by the right hand value or variable and replace variableA with the answer
D) divide variableA by the right hand value or variable and replace variableA with the answer
E) mod (divide) variableA by the right hand value or variable and replace variableA with the REMAINDER
F) div (integer divide) variableA by the right hand value or variable and replace variableA with the answer (which discards the remainder)
In Python’s print statement, how do you combine strings and variables into a single print line?
print (“price is £”, totalPrice, “ exactly”
in Python IDEs is the £ sign always handled correctly?
In some IDE’s it is and in some it is not recognised in a string and will cause the program to crash
In Python print command, can you use a ‘ + ‘ to join strings or variables?
so you first have to convert any real numbers to strings using the str(n) function
in python, when separating strings using ‘ , ‘ how can you eliminate the extra space that appears between a string and a number e.g when you get “.. £ 15.00” but you want “.. £15.00”?
Use the ‘ + ‘ and convert the number to a string using the str(n) function
In Python what function converts a number to a string?
str(n)
What is the name for the method(s) that allow you to put special characters into strings?
Escape sequences
e.g \n skips to a new line