Python Flashcards

1
Q

What is an IDE?

A

Integrated Development Environment. You can use any text editor to write code. However, most integrated development environments (IDEs) include functionality that goes beyond text editing. They provide a central interface for common developer tools, making the software development process much more efficient. Developers can start programming new applications quickly instead of manually integrating and configuring different software.

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

What are variables and how do you define them?

A

Variables are containers for storing data values. Separate space between words with underscore(“_”). Structured: variable_name = variable_value. Basically similar to JavaScript, but without variable declaration keywords like var, const, and let.

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

What are some of the data types in Python?

A

Strings, numbers, boolean, tuples

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

What are strings?

A

Text encapsulated within quotes(“”). Use \n to start a new line within a quote. Use " to print a quotation mark within a string. You can use string functions (len, index, upper, lower…etc)

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

What is concatnation?

A

Joining two or more string together.

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

What are some number functions?

A

str(): convert number to string. Used to concatenate string with numbers.
abs(): convert number to an absolute value.
pow(): pass two parameters, takes the power of the second parameter to the first one.
max(): get the max number from the parameters.
min(): get the min number from the parameters.
round(): round the number

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

How can you import other number functions?

A

from math import *. Import from the math module.

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

How to get input from user?

A

using input().
ex: name = input(“Enter your name: “)
age = input(“Enter your age: “)
print(“Hello “ + name + “! You are “ + age)

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

What is the default data type when getting input from user?

A

string. If you want to work with numbers, you need to convert user input into number. ex: int(), float()

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

What are lists? How do you define them?

A

a set of data.
ex: friends = [“Kevin”, “Karen”, “Jim”]

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

How do you access the last item on the list?

A

list[-1]

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

How do you access all of the list items after index 1?

A

list[1:]

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

How do you access second and third item on the list?

A

list[1:3]. The last number does not get included on the result

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

What are some of the List Functions?

A

extend(): allows you to add another list to a list.
append(): allows you to add an item to the end of the list.
insert(): allows you to add in a specific index. takes two parameters (index_number, “add_item”)
remove(): allows you to remove an item from the list
clear(): removes every element from the list
pop(): removes last element from the list
count(): gives you the number of times the element occurred in the list
index(): gives you the index number in the list where the element appears
sort(): sorts the list in ascending order
reverse(): reverse the list items
copy(): copy the list

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

What is a tuple?

A

similar to lists but wrap elements in () and tuples are immutable. you can make a list of tuples

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

How to create functions? How do you call functions?

A

def function_name():
function_name()

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

What is if statement?

A

evaluates a condition. If evaluated True, the code inside the body of it is executed. If not, the code inside the body of if is skipped.

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

what is get in python?

A

allows you to access values by accessing the key. You can also put in default action if the key is not found.

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

What is a while loop in python? What is the syntax?

A

allows you to execute a block of code multiple times. until the condition becomes false.
i = 1
while i <= 10:
print(i)
i += 1

print(“Done with loop”)

20
Q

What is a for loop in python? What is the syntax?

A

used for iterating over a sequence.
for letter in “Giraffe Academy”:
print(letter)

21
Q

What are 2D lists?

A

lists within a list.

22
Q

How do you write comments? What are they?

A

start a line with #. For multiple lines, write comment in between ‘'’comment’’’. Does not get recognized when running program. Also to comment out code.

23
Q

What are try and except blocks?

A

Used for error catching. Allows your program to run smoothly even when errors occurr. Always want to be specific when catching errors.

24
Q

What is the syntax for try and except?

A

try:
answer = 10/0
number = int(input(“Enter a number: “))
print(number)
except ZeroDivisionError as err:
print(err)
except ValueError:
print(“Invalid Input”)

25
Q

How do you open external files? What are some examples of mode?

A

open(“file_name”, “mode”).
“a”: append, means append information to end of file
“r+”: read and write
“r”: read

26
Q

What are some rules to keep in mind when reading files?

A

always want to check if file is readable (use readable function). always want to close file after open (use the close function). Appending you need to be careful because you can mess up the file. If you want to add on a new line, you need to add \n at the beginning. “w” mode overwrites the entire file.

27
Q

What is a module?

A

Python file that you can import into current python file.

28
Q

How do you install packages in python?

A

pip install packageName

29
Q

What are classes and objects in python?

A

Allows you to create your own data types. Class defines what a data type is. Object is the actual data. You can model real world entities and create a data type of it.

30
Q

What are class functions in python?

A

functions that can be used on the objects of the class

31
Q

What is inheritance in python?

A

allows you to inherit properties from Class to different Class

32
Q

What is python interpreter?

A

Environment you can use to run python commands. For example, you can run python commands in the terminal.

33
Q

What are docstrings?

A

similar to # for commenting out code, but allows you to put in multiple lines. prints when using help()

34
Q

How do you define default values when defining a function?

A

def greet(who=”Colin”):
print(“Hello,”, who)
who variable can be used

35
Q

What are higher order functions?

A

functions that operate on other functions

36
Q

What does list[:3] mean?

A

get the list starting from index 0 and continuing up to but not including index 3.

37
Q

What does list[3:] mean?

A

get the list starting from index 3 and continuing up to end of list.

38
Q

What does list[1:-1] mean?

A

get all the list except first and last

39
Q

What does list[-3:] mean?

A

get the last 3

40
Q

What is list comprehension?

A
41
Q

What is pandas in python?

A

data analysis and manipulation tool which includes DataFrames

42
Q

What is iloc and loc in pandas? Whats the difference?

A

Way to select specific data from a DataFrame. loc is label based and iloc is index based.

43
Q

What is set_index in pandas?

A

sets the index column to what ever column you want. This is useful if you can come up with an index for the dataset which is better than the current one.

44
Q

What are the coditional selectors in pandas?

A

isin: lets you select data whose value “is in” a list of values.
ex: reviews.loc[reviews.country.isin([‘Italy’, ‘France’])]

isnull (and it companion notnull): lets you highlight values which are (or are not) empty (NaN).
ex: reviews.loc[reviews.price.notnull()]

45
Q

What are some summary function in DataFrame?

A

describe(): This method generates a high-level summary of the attributes of the given column.
-> It is type-aware, meaning that its output changes based on the data type of the input.
mean(): shows the mean of the points allotted
unique(): shows list of unique values
counts(): To see a list of unique values and how often they occur in the dataset

46
Q

What is mapping in python pandas? What are the functions?

A

creating new representations from existing data, or for transforming data from the format it is in now to the format that we want it to be in later.

map(): expect a single value from the Series and return a transformed version of that value.
apply(): the equivalent method if we want to transform a whole DataFrame by calling a custom method on each row.