Python Flashcards

1
Q

What is Python?

A

Python is a high-level, general-purpose object oriented programming and scripting language.

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

What is a High-Level programming language?

A

A High-Level programming language is a language that has a lot Abstraction from the details of the computer. For example it will simplify or automate tasks such as Memory Management opposed to a low-level language that is usually less readable and requires direct code for dealing with the details of the computing system. Low and High are used to describe high abstraction and low abstraction.

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

How is a python variable declared?

A

variable = variable_value

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

what does the \ do in this statement:

‘Hi, I'm Anthony’

A

It is used to escape string and use a special character ( ‘ ) the example could also be written “Hi I’m Anthony” because double quotes were used around the string.

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

How do you create a single line comment in python?

A

By using the pound (hash) symbol.

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

How do you create a multiple line comment in Python?

A

”"”You start it with the quotation marks followed by the comment and then end the multi line comment with three more quotation marks”””

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

What does len( ) do?

A

len ( ) is a method that returns the string length of the string (including spaces) or variable storing a string that is passed to it.

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

What does upper( ) do?

A

It convert a string or variable storing a string to uppercase. It is written like this
“eggs”.upper( )
That would return “EGGS”

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

what does lower( ) do?

A

It converts a string or variable storing a string to lowercase. It is written like this:
“SpAm”.lower( )
that would return “spam”

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

What does str( ) do?

A

It converts what ever is passed to it into a string (accept variable names). it is written like this:
str(2.13)
Would return “2.13”

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

Why does lower( ) and upper( ) use dot notation?

A

lower( ) and upper ( ) are unique to strings so they use string literals where as len( ) and str( ) can be passed object that are not strings.

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

what does print do?

A

Print outputs the what it is passed to the console from the interpreter.

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

How do you concatenate string in python?

A

By using the plus sign (+).

“hello “ + “world”

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

what are PEPs?

A

Python Enhancement Proposals

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

What is the keyword to create a function?

A

def

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

What is a docstring?

A

is a triple quoted (“””) multi link comment that comes before the code block of the function but after the name that briefly explains what the function does.

17
Q

What is a parameter?

A

a parameter is the what you place between the parenthesis when you define a function.

18
Q

What is an argument?

A

An argument is the data that you put inside the parenthesis when you run or call the function.

19
Q

What are “splat arguments” and how are they defined?

A
Splat arguments are when you don't know how many arguments a function will be passed so can't set up the number of parameter to match. The splat arguments gives you the ability to set a arbitrary place holder that accepts however many arguments are passed to it. it is defined like this:
def funcName(*args):
    the_function
The *args can be whatever you like but that is what is usually used.
20
Q

What are the ways you can import modules?

A
  1. Generic Import
  2. Function Import
  3. Universal Import
21
Q

What is a generic import?

A

You can import the entire module using “import module_name”. When using things from this module you will have to type it’s name again i.e. module_name.module_functionORvariable

22
Q

what is a functional import?

A

Import a specific function or variable from a module. like this: from module_name import functionORvariable_name when this method is used you do not have to call the module name before using the function or variable.

23
Q

What is a universal import?

A
A universal import is when you import all of the functions and variable of a module and dump them all over the place. 
from module_name import * this makes it so you do not have to type the module_name before the function or variable but is not good practice as it is easy for conflicts to occur.
24
Q

What does min( ) do?

A

Return the smallest of the arguments passed.

25
Q

what does max( ) do?

A

Returns the largest of the arguments passed.

26
Q

what does abs( ) do?

A

Returns the absolute value (the distance from 0) of the arguments passed.

27
Q

What does type( ) do?

A

Returns the type of data that is passed as an argument.

28
Q

what are lists and how are they defined?

A

lists are multiple values assigned to on variable. and the are defined by placing square brakets around the items in you list. i.e. list = [“item1”, “item2”, “item3”]

29
Q

How do you change an item on a list?

A

By selecting the index of the list item and resetting it’s value like this:
list[2] = “item4”

30
Q

How do you add an item to a list?

A

By using the append( ) method. Like this:

list.append(“item5”)

31
Q

What is list slicing and how is it done?

A

List slicing is where you get selected items out of a list. You set a start point and an end point and it will return everything after the start point and everything BEFORE the end point. i.e. list_name[0:2] would return the 1st and 2nd items of the list.

32
Q

How do you add an item to a list at a specific position?

A

insert(index, item) where index is the postion that you want the item to be at and item is the value you want to place there.

33
Q

How to find the postion of an item in a list?

A

inde(item) where item is the value you are trying to find.

34
Q

How do sort items in a list?

A

using dot notation to call .sort( ) on the list. This will arrange the items in order of value from smallest to largest or alphabetically.

35
Q

What is a dictionary in Python?

A

A dictionary is ver similar to a list but it contains key - value pairs like this:
d = {“key1” : “value1”, “key2” : 2}
they are surrounded by curly braces.

36
Q

How do you add an item to a dictionary?

A

By choosing the dictionary and then assigning the key in side brakets followed by the equals sign and the value you want it to store.
i.e. d[“key3”] = “value3”

37
Q

How do you delete an item from a dictionary?

A

by using the del key world follow by the dictionary name and the key that you want to delete. i.e. del d[“Key1”] will delete both key1 and the value paired with it.

38
Q

How do you assign a new value to a dictionary key?

A

by just reassigning it like a variable i.e.

list[“key2”] = “Value9” key2 would now be paired with Value9 and what ever was previously assigned to it would be gone.

39
Q

How do remove an item from a dictionary based on it’s value.

A

dict_name.remove(value)