Python Flashcards

1
Q

Why Python to learn as a beginner?

A

It’s syntax is relatively simple and you don’t have to worry about things like static syntax and compilation time

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

What is homebrew?

A

It is a package manager that helps us install software on our operating system

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

Who created Python?

A

Guido Van Rossum in 1991

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

What are some popular libraries?

A

NumPy, SciPy, BeautifulSoup, Scrapy, Twisted, Django

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

How does Python know how to run code?

A

Indentation…tab or four spaces…DO NOT MIX UP

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

How would you do Python for 1 to 255

A
def print1to255():
    for i in range(1, 256):
        print i
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why version 2.7 and not 3.6?

A

Porting code over is easy, but going backwards is not so easy

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

What is a web server?

A

A computer system that processes HTTP requests

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

Why are companies using 2.7?

A

There are many reasons why this is the case, the primary being the expense of switching all of a company’s code base from one version to another

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

What is the Python shell?

A

The python shell is a command line interface we can use to interact with the Python interpreter. Once activated, we can type some Python code and see the results immediately.

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

If I divide 31/2 on the python shell command line, what is the result?

A

15, most programming languages treat integers (whole numbers) and floating point numbers, or floats (decimal numbers) differently. If you divid an integer by an integer, the result will always be an integer rounded down

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

Do you need to utilize var to declare a variable in Python?

A

No

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

What is a list in Python?

A

A list is an array

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

How can we comment out code in Python?

A

Using either # for single line, or triple quotes (double or single) for multiple lines UNLESS it’s the first line of code.

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

What are data types?

A

Data types refers to how the computer knows to classify information.

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

What are primitive data types? What are the most common?

A

Are the basic building blocks of a language.
Boolean values - Assess the truth value of something. It has only two values: True and False
Numbers - Integers (whole numbers), floating point numbers, and complex numbers
Strings - a text literal. Most pages in the web work with strings quite often

17
Q

What are composite data types?

A

Collections composed of the above primitive types.
Tuples - A type of data that is immutable (can’t be modified after its creation) and can hold a group of values. Tuples can contain mixed data types.
Lists - A type of data that is mutable and can hold a group of values. Usually meant to store a collection of related data.
Dictionaries - A group of key-value pairs. Dictionary elements are indexed by unique keys which are used to access values.

18
Q

Indentation, explain it’s significance

A

Python has no brackets, braces, or keywords to indicate the start and end of certain code blocks such as functions, if statements, and loops. The only delimited is the colon :

19
Q

What is the equivalent of function in python?

A

def

20
Q

How can you print a string with a variable?

A

print “my name is”, variable

print “my name is” + variable

21
Q

What is string interpolation?

A

Utilizing a method to inject variables into your string.

first_name = “Zen”
last_name = “Coder”
print “My name is {} {}”.format(first_name,last_name)

22
Q

What are the most commonly used string methods?

A

string. count(substring): returns number of occurrences of substring in string.
string. endswith(substring): returns a boolean based upon whether the last characters of string match substring.
string. find(substring): returns the index of the start of the first occurrence of substring within string.
string. isalnum(): returns boolean depending on whether the string’s length is > 0 and all characters are alphanumeric (letters and numbers only). Strings that include spaces and punctuation will return False for this method. Similar methods include .isalpha(), .isdigit(), .islower(), .isupper(), and so on. All return booleans.
string. join(list): returns a string that is all strings within our set (in this case a list) concatenated.
string. split(): returns a list of values where string is split at the given character. Without a parameter the default split is at every space.

23
Q

How would you add information to a list?

A

.append()

24
Q

What is the equivalent of array.slice(start, end not inclusive)?

A

x[1:4]

25
Q

what is the similar function to javascript .length?

A

len(sequence)…can be applied to all sequences, including tuples and strings

26
Q

What are some useful built-in functions for sequences?

A

Some built-in functions for sequences:
enumerate(sequence) used in a for loop context to return two-item-tuple for each item in the list indicating the index followed by the value at that index.

map(function, sequence) applies the function to every item in the sequence you pass in. Returns a list of the results.

min(sequence) returns the lowest value in a sequence.

sorted(sequence) returns a sorted sequence

27
Q

What is a type?

A

int, boolean, string, list,

when creating a dictionary, indentation requirements are not as strict

28
Q

for x in mydictionary: print x, mydictionary[x]

A

Dictionaries are good for more structure. Storing user information you can use a dictionary and it’s a lot easier

29
Q

What is a set?

A

a = {1,2,3,4,5} and you can subtract a set from another set