Class Review Flashcards

1
Q

True or False: Python is a proprietary, expensive, difficult-to-learn language owned by Microsoft?

A

False

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

What is a literal?

A

A hard-coded instruction - literally this string, this number, etc.

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

What is the character for single-line comments?

A

#

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

What is the escape sequence for a single quote within a string?

A

'

‘I don't want eggs for breakfast.’

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

What is the character limit for a single line according to the Python Style Guide?

A

79 characters

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

What are the three keywords for conditional “IF” flow control structures?

A

if, elif, else

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

Does python use braces for controlling application flow?

A

No - it uses tabs - spacing!

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

Does python use static or dynamic data typing for variables? (Hint: duck typing)

A

Dynamic typing - duck typing - if it walks like a duck and acts like a duck… it’s a duck!

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

What do we call objects that can return their members one at a time?

A

Iterables

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

What are Python lists similar to in other languages?

A

Arrays

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

Which types of sequences are immutable?

A

Tuples, strings

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

What are generator expressions?

A

Iterables that can only be iterated through once

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

When files are read into python, what does python store them in?

A

File objects

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

What are the different options to sort on with the sorted function?

A

Existing functions, lambda functions, reversed

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

Does python provide keywords for handling exceptions?

A

Yes! Try, except, else, finally.

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

Can you create custom functions in python?

A
Yes!
def [function name](parameter):
    # pass
17
Q

What are the different ways for one module to use another?

A

from [module] import [function]
from [module] import *
import [module]

18
Q

What is the .pyc extension file?

A

compiled python files

19
Q

Where does python search for modules?

A

Current directory, standard library, and sys.path

20
Q

What are some of the string methods commonly used in our class?

A

string. join(sequence) - shortcut for a for loop for joining strings
string. split(‘delimiter’) - split by character within parens - default space
string. lower() - lowercase
string. strip(‘character’) - strip characters from both sides of string - default all whitespace

21
Q

How do you format strings in python? (new way)

A

f’string {variable} {expression}

‘string {index 0} {index 1}’.format(variable, expression)

22
Q

How do you read arguments from the command line?

A

import sys

sys. argv is a list of arguments
sys. argv[0] = file name

all other arguments separated by space on command line.

23
Q

What are two ways to short-circuit a loop?

A

continue - go to the top of the loop

break - exit out of the loop and move on to the next code (if any)

24
Q

How do you slice an array? Bonus: how do you slice an array backwards?

A

[start:stop:step] default start: 0; default stop: end of array; default step: 1

index 0 through 10:
[:11]

index 2 through 14 by 2s:
[2:15:2]

backwards by 5s:
[30:0:-5]