AtBS 1-6 Flashcards

(70 cards)

1
Q

An interactive shell is

A

a program that lets you type instructions into the computer and run one at a time

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

A file editor is..

A

Similar to a text editor, can write whole program in it to be run

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

How to print something to the shell?

A

print(‘Message’)

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

How to find length of a string?

A

print(len(myString))

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

How to write an if statement in Python?

A

if variable ==’input’:

do something

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

How to add else statement to if statement?

A

if variable ==’input’: do something

else: do something else

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

What does elif mean?

A

Else If

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

How to comment in Python

A

Use the pound sign #

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

Key command to interrupt Python?

A

Ctrl+C

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

What does a continue statement do?

A

Jumps back to the start of the loop to reevaluate the loops condition

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

What does a break statement do?

A

It gets out of loop if execution leads to it.

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

How to input a number as an integer?

A

Variable=int(input())

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

Formula for Gauss Loop

A

total=0

for num in range(101):

total=total+num

print(total)

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

What is the standard library?

A

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

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

An argument is..

A

The value that a function evaluates ex print(‘argument’) len(argument)

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

What are the three boolean operators?

A

and

or

not

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

What are the six comparison operators?

A

>

<

<=

>=

==

!=

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

How to handle exceptions?

A

Use Try and Except

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

What is a return value?

A

It is the value that a function evaluates to

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

If you had a function name bacon() in a module name spam, how would you call it after importing spam?

A

Can be called with spam.bacon

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

Syntax to create a list

A

spam=[‘cat’,’bat’,’rat’,’elephant’]

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

Syntax to add to a list

A

spam=spam+[‘pteradactyl’]

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

Delete rat from following list [‘cat’, ‘mouse’, ‘rat’, ‘elephant’, ‘pteradactyl’]

A

del spam[2]

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

What do the in and not in operators do?

A

They can check whether a value is in a list or not.

They evaluate to True or False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is an augmented assignment operator?
Instead of spam=spam+1 do spam+=1 This is shorter
26
How to find the position of a value in a list?
Use index method to find it spam.index(value)
27
How to add a value to a list?
use append method to add to a list spam.append('value')
28
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
29
How to replace a value in a list?
spam[num in list] = new value
30
How to remove a value in a list?
Use remove method spam.remove(value)
31
How to sort values in a list?
Use sort method spam.sort()
32
How to reverse sort in a list?
spam.sort(reverse=True)
33
What is a tuple?
Like list but they are immutable and typed in parentheses ()
34
When you assign a list to a variable, what are you actually assigning?
You are actually assigning a reference and not the values themselves
35
How to make separate copies of lists and not just references?
import copy module use copy.copy() function for lists for list within list use deepcopy() function
36
How to create a dictionary? Dictionary Format
Use curly brackets myCat={'size':'fat'} Dictionary Name = {'Key':'Value'}
37
How are dictionaries different than lists?
Dictionaries are unordered Lists are ordered
38
What are the advantages of dictionaries?
Dictionaries give the ability to have arbitrary keys. ie name, age etc
39
How to print all values in a dictionary?
for v in spam.values(): print(v)
40
How to print all keys in a dictionary?
for v in spam.keys(): print(v)
41
What is the combination of both a dictionary key and value called? 'key':'value'
It is called an item
42
What does the get() Method do? Syntax
It uses a key of a value to retrieve and a fallback option if that key is not found in a dictionary ex spam.get('key','fallback')returns either the value of the key inputted or 'fallback'
43
What does the setdefault() method do? Syntax
It places a key and a value in a dictionary if not already there spam .setdefault ('key', 'value')
44
What does pprint function do to dictionaries? Syntax
Prints the dictionary vertically pprint.pprint(DictName)
45
How to change a value in a dictionary? Syntax
Dict\_Name['key'] = 'value'
46
How to get pprint to only go to one line for each item to print in a dictionary?
pprint(DictName, width=1)
47
What can having double quotes do for a string? Example
They allow you to have a single quote character in the string. Example "This is Alice's cat."
48
What is an escape character and what does it let you do?
It is character that lets you use other characters that you normally cannot use In Python it is the backslash \
49
Escape character to use Single quote? Double quote?
\' \"
50
Escape character to Tab Linebreak Backslash
\t \n \\
51
What is a raw string? Syntax When is it useful?
A raw string completly ignores all escape characters and will print the entirety between quotes as a string. print(r'That is Carol\'s cat.') It is useful for regular expressions.
52
What is a multiline string?
A multiline string starts off with 3 single or double quotes It lets you type multiple lines as a string It ends with 3 single or double quotes
53
How to write multiline comments in python?
""" use the multiline string of 3 quotes before comments and 3 quotes after """
54
How does slicing a string work? spam='Hello World' spam[0] returns spam[0:2] returns
If you specify one index position Python returns that position in a string If you specify a range Python includes beginning index but not the ending index spam[0] returns 'H' spam[0:2] returns 'He'
55
spam='Hello World!' slice the string to say 'Hello' slice the string to say 'World!'
spam[:5] 'Hello' spam[6:] 'World!'
56
spam='Hello World!' What would the methods spam = spam.upper() spam = spam.lower()
upper() ='HELLO WORLD!' lower()= 'hello world!'
57
What does isupper() and islower()
Return True if all letters are upper or lower False if no letters or a mix of upper and lower
58
What do the following methods do? isalpha() isalnum() isdecimal()
isalpha() True if all letters isalnum() True if only numbers and letters isdecimal() True if only numbers
59
What do the following methods do? isspace() istitle()
isspace() True if string only spaces, tabs and newlines istitle() True if string only has uppercase letter folowed by undercase
60
What do the startswith() and endswith() methods return?
The return either true or false if a string begins or ends with the value ex spam=('The world') spam.startswith('The') returns True
61
What does the join property do? Syntax?
Join a series of strings into one string ' '.join(['My','name', 'is', 'Simon']) 'My name is Simon' or ' @'.join(['My','name', 'is', 'Simon']) 'My @name @is @Simon'
62
What does the split method do?
It splits one string into multiple strings, usually based on whitespace but you can set it for other items as well 'My name is Simon'.split('m') ['My na', 'e is Si', 'on']
63
What kind of brakets for: list dictionary tuple
list [] dictonary{} tuple()
64
What do the rjust() and ljust() methods do? Syntax?
They return a padded version of the string that they are on. 'Hello'.rjust(10) returns ' Hello'
65
What does 'Hello'.rjust(20,'\*') return?
'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*Hello'
66
What does 'Hello'.center(20,'$') return
'$$$$$$$Hello$$$$$$$$'
67
What do the strip(), rstrip() and lstrip methods do?
Remove whitespace from string. L and R remove it from left and right sides OR it can specify certain charcters to be stripped from the ends
68
spam='Blue Bell Ice Cream' What will spam.strip('amBl') return?
'ue Bell Ice Cre'
69
How to install third party modules?
Open command line pip install ModuleName
70
How to copy text from clipboard so python can use it?
New Variable=pyperclip.paste()