Python Flashcards

1
Q

Python3 features

A

Free and open sources
Object oriented Language
Portable- use on Mac, Linux, Unix
Interpreted Language- executed line by line bot compled
Dynamically typed - No need to declare var types
Automatic memory management
built-in data structures
Functions are first class objects that make difficult tasks simple

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

Python Memory Management

A

Memory management in Python involves a private heap containing all Python objects and data structures. The management of this private heap is ensured internally by the Python memory manager. The Python memory manager has different components which deal with various dynamic storage management aspects, like sharing, segmentation, preallocation or caching.

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

Error handeling

A

Try:
this block of code
Except:
do this if you hit an error

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

Lists

A

Mutable
Ordered collection of items
Can store any sort of object
some functions you can do: Slice, delete, insert, pop, reverse
Lists are great to use when you want to work with many related values. They enable you to keep data together that belongs together, condense your code, and perform the same methods and operations on multiple values at once
Opt for a list when you need an ordered sequence of items

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

Dictionary

A

Do you need to associate values with keys, so you can look them up efficiently (by key) later on? Use a dictionary.
Mutable
Unordered
Unique keys

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

Tuple

A

Immutable
Ordered
When you want to collect an immutable ordered list of elements, use a tuple. (For example, when you want a (name, phone_number) pair that you wish to use as an element in a set, you would need a tuple rather than a list since sets require elements be immutable).

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

Sets

A
Unordered
Distinct
Commonly used to remove dupes
mutable
When you want an unordered collection of unique elements, use a set. (For example, when you want the set of all the words used in a document).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

algorithim

A

A set of specific steps for solving a category of problems

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

high level language

A

A programming language like Python that is designed to be easy for humans to read and write.

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

list comprehensions

A

Best to use when you need to create a new list from other iterables

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

For loop

A

Used to iterate through elements of an array or a list

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

While loop

A

Perform and indefinite number of iterations as long as a condition remains true

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

NumPy

A

one of the principal packages for data science applications
often used to process large multidimensional arrays, extensive collections of high-level mathematical functions and matrices
Implementation methods make it easy to conduct multiple operations with these objects

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

Pandas

A

Python is a powerful tool for data analytics which comes with a variety of built-in methods for combining, filtering, and grouping data.

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

Modules

A
Files containing Python code, can be functions, classes, or variables. Some common built-in modules are
os
sys
math
random
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Global variables

A

Variables declared outside a function or in global space are global variables. Can be accessed by any function in the program

17
Q

local variables

A

declared inside a functions and can only be accessed within

18
Q

Init

A

init is a method or constructor in Python that is automatically called to allocate memory when a new object/instance of a class is created

19
Q

lambda

A

an anonymous function can have any number of parameters bu just one statement

20
Q

Break

A

allows loop termination when some condition is met and the control is transferred to the next statement

21
Q

Continue

A

Allows skipping some part of loop when some specific condition is met and the control is transferred to the beginning of the loop

22
Q

Combine objects method

A

zip(list1,list2)

combined_zip)list = [*combined_zip]

23
Q

Create a dict counting how many times a value in a list appears in that list

A

from collections import Counter

type_counts = Counter(list)

24
Q

how to make combinations

A

from itertools import combinations

combo = list(combinations(list to combine, values per combo)

25
Q

Set methods

A

comparing two sets
intersection: all elements that are in both sets
ex) set_a.intersection(set_b)
difference: all elements in one set but not the other
symmetric_difference(): all elements in exactly one set
union(): all elements that are in either set

26
Q

numpy methods

A

np. mean(list, axis (1 will be row based 0will be column)
np. sum(list, axis if you want)
np. subtract(array1, array2)

27
Q

method that creates a list of numbers

A

range(start, stop (will not include this number), step)

28
Q

index, values of a list method

A

enumerate(list, start=start index)

29
Q

apply a function to each element in a list

A
map(function to use, list)
ex) 
def addition(n):
n+n
numbers = (1,2,3,5)
output of list(map(addition,numbers))
[2,4,6,10]