AtBS 1-6 Flashcards
An interactive shell is
a program that lets you type instructions into the computer and run one at a time
A file editor is..
Similar to a text editor, can write whole program in it to be run
How to print something to the shell?
print(‘Message’)
How to find length of a string?
print(len(myString))
How to write an if statement in Python?
if variable ==’input’:
do something
How to add else statement to if statement?
if variable ==’input’: do something
else: do something else
What does elif mean?
Else If
How to comment in Python
Use the pound sign #
Key command to interrupt Python?
Ctrl+C
What does a continue statement do?
Jumps back to the start of the loop to reevaluate the loops condition
What does a break statement do?
It gets out of loop if execution leads to it.
How to input a number as an integer?
Variable=int(input())
Formula for Gauss Loop
total=0
for num in range(101):
total=total+num
print(total)
What is the standard library?
It is the set of modules that Python comes with; Each module has a related group of functions that can be used in programs ex. random and math module
An argument is..
The value that a function evaluates ex print(‘argument’) len(argument)
What are the three boolean operators?
and
or
not
What are the six comparison operators?
>
<
<=
>=
==
!=
How to handle exceptions?
Use Try and Except
What is a return value?
It is the value that a function evaluates to
If you had a function name bacon() in a module name spam, how would you call it after importing spam?
Can be called with spam.bacon
Syntax to create a list
spam=[‘cat’,’bat’,’rat’,’elephant’]
Syntax to add to a list
spam=spam+[‘pteradactyl’]
Delete rat from following list [‘cat’, ‘mouse’, ‘rat’, ‘elephant’, ‘pteradactyl’]
del spam[2]
What do the in and not in operators do?
They can check whether a value is in a list or not.
They evaluate to True or False
What is an augmented assignment operator?
Instead of spam=spam+1
do spam+=1
This is shorter
How to find the position of a value in a list?
Use index method to find it spam.index(value)
How to add a value to a list?
use append method to add to a list spam.append(‘value’)
How to insert a value to a list?
use insert method to add to a list spam.insert(position num,value) This does not replace the value