C4: Python for Data Science, AI & Development Flashcards

1
Q

str()

A

String data type object.

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

int()

A

Integer data type object.

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

float()

A

Floating Point data type object.

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

list()

A

Returns a list of the elements in an object.

E.g.,

Var = “Panks”
list(Var) : (“P”,”a”,”n”,”k”,”s”)

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

int(3.55):?

A

3

Here you are casting a floating point through a integer data type, which may have strange results.

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

float(15):?

A

15.0

Here you are casting a integer into a floating point data type.

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

str(4.558):?

A

“4.558”

Here you are casting a floating point number into a string data type

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

What are the two Boolean expressions in Python?

A

True & False*.

They must be camel case.

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

int(True):?

A

1

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

int(False):?

A

0

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

bool(1):?

A

True.

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

bool(0):?

A

False.

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

What is an Operand?

A

The thing to be operated on.

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

What is an Operator?

A

What the Operand opperates on.

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

type()?

A

Returns the data type of variable.

Good for debugging.

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

What’s Typecasting?

A

Converting one data type into another.

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

Define Tuple.

A

1) An Ordered set of numbers.
2) Where the order cannot change.

  • The sequence cannot be changed.
  • Set is finite.
  • Set may contain duplicates.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

n-tuple

A

(X1, … , Xn)

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

What does RegEx mean?

A

Regular Expression.

  • A Python module.
  • A tool for matching and handling strings.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

> > > import re

A

Imports the Regular Expression module built into Python 3.

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

Concatenation

A

Combines strings.

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

Major Data Type Objects in Python.

A

Integers
Floating Points
Strings
Booleans

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

Coupoud Data Type Objects? - Python

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

Tuples syntax? - Python

A

var = (X1,X2,…,…,Xn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
For var = **(X1,X2,...,...,Xn)**, var[0] returns?
X1
26
**Slicing** syntax? - *Python*
[ *n1*:*n2*:*n3*] Where: * n1 = The first index position to return. * n2 = The last index position to pull, +1. * n3 = The stride, if any.
27
Immutable? - *Python*
Cannot be changed. E.g., * Strings. * Tuples.
28
List syntax? - *Python*
var = **[X1,X2,...,...,Xn]**
29
Difference between Lists and Tuples?
Lists are mutable. Tupples are not.
30
*var* = [33,55,2,10] *var***.extend**([9,19]) ?
print(*var*) : [33,55,2,10,9,19]
31
*var* = [33,55,2,10] *var***.append**([9,19]) ?
print(*var*) : [33,55,2,10,[9,19]]
32
*var* = [33,55,2,10] **del**(*var*[1]**)** ?
*var* = [33,2,10]
33
What method would you use to convert a string to a list?
**.split()** E.g., str("The rain in spain") str2 = str.split() str2 = ["The","rain","in","spain"] *() is blank, the delimiter is *space*. Otherwise, pass in a delimiter, such as a colon*.
34
Define **Aliasing**.
Multiple names refering to the same object.
35
A = [X1,X2,...,...,Xn] B = A list(B) = ?
[X1,X2,...,...,Xn]
36
A = [X1,X2,...,...,Xn] **B = A[:]** A[2] = 100 list(A) = ? list(B) = ?
A = [X1,X2,100,...,...,Xn] B = [X1,X2,...,...,Xn] ***A[:]*** *clones the list in variable A.*
37
**copy()** - *Python*
A **Method** used to create a shallow copy of a list.
38
**count()** - *Python*
A **Method** used to count the number of occurrences of a *specific element* in a list.
39
Define these **list methods**: Below, let *"var"*, be any variable that holds a list: var`.pop()` var`.reverse()` var`.sort` var`.remove()` var`.insert()` var`.count()` var`.copy()`
* `pop()` method is another way to remove an element from a list in Python. It removes and returns the element at the specified index. If you don't provide an index to the `pop()` method, it will remove and return the last element of the list by default * The `reverse()` method is used to reverse the order of elements in a list * The `sort()` method is used to sort the elements of a list in ascending order. If you want to sort the list in descending order, you can pass the `reverse=True` argument to the `sort()` method. * To remove an element from a list. The `remove()` method removes the first occurrence of the specified value. * The `count()` method is used to count the number of occurrences of a specific element in a list in Python. * The `copy()` method is used to create a shallow copy of a list.
40
**Dictionaries** object syntax?
`{'`A`':'`a`','`B`':'`b`',...,...,'`N`':'`n`'}`
41
Dictionary attributes.
* Keys must be unique. * Keys are immutable. * -- * Values are mutable * Values don't have to be unique.
42
Assume: `{'Key1':'Value1','Key2','Value2',...,...,'KeyN','ValueN'}`. -- If: **`Dict['Key2']`** :
Value2
43
Assume: `{'Key1':'Value1','Key2','Value2'}`. -- If: **`Dict['New1'] = 100`** :
`{'Key1':'Value1','Key2','Value2','New1':100}`.
44
Assume: `{'Key1':'Value1','Key2':'Value2','New1':100}`. -- If: **`del(Dict['Key1'])`** :
{'Key2':'Value2','New1':100}
45
Assume: `{'`A`':'`a`','`B`':'`b`',...,...,'`N`':'`n`'}` -- Query this Dictionary for B.
**`'B' in Dict`** returns `True`
46
`Dict.keys()` : ?
This method lists all the keys in the Dictionary.
47
`Dict.values()` : ?
This method lists all the values in the Dictionary.
48
**`Set`** properties?
* Unordered. * Containes no duplicate values.
49
**`Set`** object syntax?
`{`3`,`1`,`2`,...,...,`N`}`
50
Typecast a `List` into a `Set`.
`set(`list[x,y,z]`)`
51
Assume: `var = [3,58,5,5,10,10,8,6]` -- `set(var)` : ?
**{3,58,5,10,8,6}** ***Note:** A set cannnot contain duplicates. They are removed from the list.*
52
Assume: `var = {'lake','fire','water'}` -- `var.add('smores')` `var` : ?
`{'lake','fire','water','smores'}`
53
Assume: `var = {'lake','fire','water','smores'}` -- `var.add('fire')` `var` : ?
**`var = {'lake','fire','water','smores'}`** ***Note:** A set cannnot contain duplicates. "fire' cannot be added.
54
Assume: `var = {'lake','fire','water','smores'}` -- `var.remove('fire')` `var` : ?
`var = {'lake','water','smores'}`
55
Assume: `var = {'lake','fire','water','smores'}` -- **'lake'** `in` **var**: ?
True
56
Set Theory *- Intersection* Assume: `Set1 = {1,2,3,4}` `Set2= {3,4,5,6}` **Instruct Python to find the *intersection* of both sets.**
Set3 = Set1 `&` Set2 ``` *Set3 : {3,4}*
57
Set Theory *- Union* Assume: `Set1 = {1,2,3,4}` `Set2= {3,4,5,6}` **Instruct Python to find the *union* of both sets.**
Set3 = Set1`.union(`Set2`)` ``` *{1,2,3,4,5,6}*
58
What method clears all the entries from a Dictionary?
var.`clear()`
59
List the six common **Comparison Operators**.
A **==** B - Is A equal to B? A **!=** B - Is A *not* equal to B? A **>** B - Is A greater than B? A **<** B - Is A less than B? A **>=** B - Is A greater or equal to B? A **<=** B - Is A less or equal to B?
60
**Comparison Operators** return what?
`True` or `False`. *These are boolean.*
61
**'Baxter'** `==` **'Baker'**: ?
`False` ``` ***Note:*** *String data types _can_ be compared.*
62
`if` syntax?
`if(`condition`) :` *Execute if true.* ______`Indented code.` ______`Indented code.` ``` ***Note:*** *Indents are _required_.*
63
`if / else` syntax?
`if(`condition`) :` *Execute if true.* ______`Indented code.` ______`Indented code.` `else:` *Execute if above is false.* ______`Indented code.` ______`Indented code.` ``` ***Note:*** *Indents are _required_.*
64
`if / elif / else` syntax?
`if(`condition`) :` *Execute if true.* ______`Indented code.` ______`Indented code.` `elif(`condition`) :` *Execute if above is false & this is true.* ______`Indented code.` ______`Indented code.` `else:` *Execute if both above are false.* ______`Indented code.` ______`Indented code.` ``` ***Note:*** *Indents are _required_.*
65
Logic Operators ?
`not()` `or()` `and()` *Python supports these three logic operators.*
66
if(True) `and` (False): ?
False
67
if(True) `or` (False): ?
True
68
**range(N)** or **range(0,N)**
[0,1,2,...,...,N-1] ***Note:*** * *The last value of arange function is always **one less** than the number input into the function.* * *A range sequence always starts at **0***. * *N must be a an **whole number***.
69
**range(10,15)** : ?
[10,11,12,13,14]
70
`i` in **`for`** loops?
`Index` or `increment`.
71
Incement `i` by 1. Decrement `i` by 5.
i `+=` 1 i `-=` 5
72
`for` syntax?
`for` counter `in` iterable object `:` ______`Indented code.` ______`Indented code.` ``` ***Note:*** * *`for` will increment the **"counter"** at the end of each loop.* * **"counter"** *can be any variable that can hold an integer data type. It is usualy `i`. * It is a temporary variable that is constrained in scope to the loop.*
73
`while` syntax?
`while` some conditional True `:` ______`Indented code.` ______`Indented code.` ***Note:*** * *It is not uncommon to itterate some counter variable within the `while` loop.*
74
`list(enumerate(range(11)))` : ?
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9) (10,10)]]
75
`Function` syntax ?
`def` **function_name**`(`*Argument(s)*`):` ______""" ______Notes ______""" ______`Indented code.` ______`return` **b** ``` ***Note:*** * *Functions cannot have an empty body. Use `none` in the body satsify this requirement that the function not be blank.* * *You do not have to define a `return` in a function.*
76
Do Local Variables confilict with Global Variables?
**No.** Variables inside a functon do not change variables outside a function, even if they have the same name.
77
What will Python do if if finds an undefined variable in a function?
Check for the variable in the global scope.
78
What does `pass` do in a function?
* **Acts as a temporary placeholder for future code.** * It ensures that the code remains syntactically correct, even if it doesn't do anything yet. * Doesn't perform any meaningful action. When the interpreter encounters “pass”, it simply moves on to the next statement without executing any code.
79
Define **Global Scope** variables.
Variables defined outside functions; accessible everywhere.
80
Define **Local Scope** variables.
Variables inside functions; only usable within that function.
81
What does `global` do in a function?
**Changes the scope of a variable in the function from local to global.** Meaning that it can be referenced even after the function has completed.
82
How would you modify the following function to allow you to pass in a variable number of arguments? ``` `def` **a_function**`(`*argument*`):` ______""" ______Notes ______""" ______`Indented code.` ______`return` **b**
**Place an asterisk before the argument.** ``` E.g., *`def` **a_function**`(`* *argument`):`
83
`Try` syntax?
`try:` ______code or pass `except` *Exception*`:` ______code or pass `except` *Exception*`:` ______code or pass `else:` ______code or pass `finally:` ______code or pass
84
Complete the sentence: **Methods are "..." with Objects.**
*...how you change or interact...*
85
Class > Object > **?** > Method
Attribute.
86
**?** > Object > Attribute > Method
Class
87
Class > **?** > Attribute > Method
Object
88
Class > Object > Attribute > **?**
Method
89
A **class** is a template for?
Objects.
90
**Class** syntax?
`class` *className*`():` ______`class_attribute = value` ______`def` `_``_``init``_``_``(self,` attribute1, attribute2, ...`):` ____________`self.attribute1 = attribute1` ____________`self.attribute2 = attribute2` ____________`...` ______def method1(self, `parameter1, parameter2, ...`):` ____________`Method logic` ____________`...` ``` * Class attributes (shared by all instances). * Constructor method (initialize instance attributes). * Instance methods (functions). Do not have to have a value passed.
91
An objects attributes define it's?
**State**. A.k.a., The data that describes the object.
92
An objects methods define it's?
**Behavior.** A.k.a., Actions assigned to the object that can change it's *state.*
93
An Object is an ... of a Class?
Instance.
94
Name the two loop controls.
Break. Continue.
95
What does `dir(`*object*`)` do?
**Returns all properties and methods of the specified object**, without the values.
96
Open a file syntax?
`open(`*.../path/filename.txt`,`'**x**'`)` ``` *Where:* * *The value of **x** may be: * **r** for reading mode. * **w** for writing mode. * **a** for appending mode.
97
fileObject**.name()** returns?
**The name of the file** in the file object.
98
*Open the following file in append mode inside a file object named* `darth` *:* ``` **.../path/tothe.darkside**
`with` `open('`*.../path/tothe.darkside*`','a') as darth`
99
fileObject**.read()** ?
**Reads the entire content of the file.** e.g., darth = *vader*`.read()`
100
fileObject**.read(**`x`**)** ?
**Reads **`x`** characters starting from the current position of the file pointer.** e.g., darth = *vader***.read(**`10`**)**
101
fileObject**.readline()** ?
**Reads the contents of a file line by line.** *Note, it remembers where it last read. Then _itterates_ and reads the next line if called again. Also, if given an integer as an argument, it will read tham many posisitons of that line. But _only_ from that line.*
102
fileObject**.seek(x)** ?
**Moves the files pointer to a specific position in the file. Then reads that character.** *The position is specified in bytes, so you'll need to know the byte offset of the characters you want to read.*
103
fileObject**.close()** ?
**Closes a file.** _This is essential._ *However, you should not have to use this if you are using the *`with`* method.*
104
Create a new file in the local directory named `obiwan.master` mapped to a file object named `jedi`.
`with open('`*.../path/tothelight/*`obiwan.master','w') as jedi:` ``` *Note:* **If the file requested by open _does not exist_ in the directory, the action will create it.**
105
**Dependencies** is another name for ?
Libraries.
106
**.tell()** does what?
Returns where the system caret `^` is in the file object.
107
Diferentiate the following; `.readline() .readlines()`
`.readline()`: This method returns one full line from the file object as a string. `.readlines()`: This method returns all the line in a file object as a list.
108
How do you querying a variable for it's attributes and methods?
`dir(`*var*`)`
109
Load pandas?
`import` *pandas* `as` pd
110
*With pandas imported:* `df.head()` does what?
Prints the first five rows of the data frame.
111
* *With pandas imported:* * *Assume `var` is a dictionary.* ``` How would you cast the dictionary into a dataframe?
varInFrame = `pd.DataFrame(`*var*`)`
112
*With pandas imported:* When you cast a *dictionary* into a *data frame*, the **values** become?
Columns. ``` *The keys become the column headers.*
113
*With pandas imported:* How would you pull an entire column(s) from a data frame and make it a new object?
var =` df [[ ` *'key1' , 'key2' , 'key5'* `]]` *Double brackets extracts a column by key (header)name.*
114
* *With pandas imported +* * *An active data frame, `df`:* How would you reference cell **a1**?
df.`iloc[0,0]`
115
*With pandas imported:* Read a *decks.csv* into the data frame object, `df`.
`df` = `pd.read_csv('`*decks.csv*`')`
116
* *With pandas imported:* * *Assume:* `data = [10, 20, 30, 40, 50]` **Create a series in series object** `s` **from this list.**
s = pd.Series(data)
117
Diferentiate, print(df.`iloc`[n]) *from* print(df.`loc`[n])
`iloc` **accesses the row by _position_.** *iloc[row_index, column_index]* *i.e., index location.* **Counts from 0.** ``` `loc` **acesses the row by _label_** *loc[row_label, column_label]* *Use method set_index() to set a columns contents as the index from the default.* **Counts from 1.**
118
Pandas generally provides **two data structures for manipulating data,** They are?
Data Frames. Series.
119
df`.iloc[1:3]` vs. df`.iloc[1,3]`
The first **slices** out and returns rows 2 & 3. The second **selects** the data a row 2 / column 3.
120
What is `df.iloc[0:2, 0:3]` doing?
Slicing out the first two rows, three columns deep.
121
NumPy stands for?
Numerical Python.
122
NumPy is meant for working with?
* Arrays * Linear algebra * Fourier transforms * Matrices
123
The 'Pandas library' is built on?
The NumPy library.
124
Syntax for making a **2D array** in Python with`NumPy`?
my_2d_array = `np.array [` _________________________`[0,0,0,0,0,0],` _________________________`[0,0,0,0,0,0],` _________________________`[0,0,0,0,0,0],` _________________________`[0,0,0,0,0,0],` _________________________`[0,0,0,0,0,0],` _________________________`],`
125
if `var` is an numpy array what do these methods do? var**.dtype** var**.size** var**.ndim** var**.shape** var**.dot()** var**.mean()** var**.max()** var**.min()** var**.std()**
`.dtype` returns the type of the data stored in the array. `.size` returns the number of elements in the array. `.ndim` returns the number of dimensions of the array. `.shape` returns the length of each dimension of the array. `.dot(a,b)` returns the dot product of the np arrays a and b. `.mean()` returns the mean value of the array. `.max()` returns the max value of the array. `.std()` returns the standard deviation of the array.
126
**np.pi** ?
Return the value of pi.
127
**np.linspace(a,b,c)**
**np.linspace(a,b,c)** returns a line (a list) starting at 'a' and ending at 'b' with 'c' evenly spaced intevals as a array. (Which include the intervals 'a' and 'b'.
128
What does **URI** stand for?
**Uniform resource identifier.** This is distinct from a *URL*.
129
What are the four HTTP methods?
**GET**: Retrieves data from the Server or API. **POST**: Submits data to the Server or API. **PUT**: Updates data on the Server or API. **DELETE**: Deletes data on the the Server or in the API.
130
What does the `Requests` library do?
Allows you to make HTTP 1.1 requests from within Python.
131
A URL has three parts. They are?
**Scheme. Address. Path.** e.g., https:// www.google.com /a/admin/login
132
Which contanins which? URL URI
**Uniform Resource Identifier > Uniform Resource Locator** or *URI {URL}*
133
What are the 5 HTTP **response status code classes** and their general meaning?
100: *Info.* 200: *Success.* 300: *Make a choice.* 400: *Failure*. 500: *Big failure.*
134
HTML tags hierarchy?
Parent > Child > Decendent Siblings = Siblings
135
What is `Beautiful Soup`?
A module that facilitates webscraping.
136
What does **DOM** stand for?
Document Object Model
137