DataCamp: Python Basics - Functions Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

get the length of a string

A

len(stringVar)

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

get definition of a function

A

help(funcName) or ?funcName

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

What shows that an argument is optional?

A

Brackets. Complex(real [, imag]) (imag is optional)

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

specify which args you’re passing (eg, if you’re skipping an arg and need to be specific)

A

function(arg1=2, arg3=5) (skipped arg2)

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

What is a method?

A

Method is called on an object, and can access the data in that object

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

upper case, lower case string methods

A

str.upper(), str.lower()

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

Count the instances of a substring in a string

A

string.count(“xxx”)&raquo_space; counts number of “xxx” in string (case sensitive)

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

return the index of the element 19 in a list

A

list.index(19)

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

count the number of times 5 appears in a list

A

list.count(5)

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

List methods to append, remove and reverse

A

list.append(), list.remove(), list.reverse()

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

what is a python package

A

Directory of scripts you can use

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

What is each script in a package called?

A

Module

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

What is a python package to help manage packages?

A

pip

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

Once you have pip, how do you install a package?

A

pip3 install package

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

To use a package in your script, or a method in the package

A

import packageName as pN

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

How do you use function1 from imported package?

A

package.function1()

17
Q

How do you import just function1 from package

A

from package import function1

18
Q

how do you import a subpackage

A

import package.subpackage