DataCamp: Python Basics - Functions Flashcards
get the length of a string
len(stringVar)
get definition of a function
help(funcName) or ?funcName
What shows that an argument is optional?
Brackets. Complex(real [, imag]) (imag is optional)
specify which args you’re passing (eg, if you’re skipping an arg and need to be specific)
function(arg1=2, arg3=5) (skipped arg2)
What is a method?
Method is called on an object, and can access the data in that object
upper case, lower case string methods
str.upper(), str.lower()
Count the instances of a substring in a string
string.count(“xxx”)»_space; counts number of “xxx” in string (case sensitive)
return the index of the element 19 in a list
list.index(19)
count the number of times 5 appears in a list
list.count(5)
List methods to append, remove and reverse
list.append(), list.remove(), list.reverse()
what is a python package
Directory of scripts you can use
What is each script in a package called?
Module
What is a python package to help manage packages?
pip
Once you have pip, how do you install a package?
pip3 install package
To use a package in your script, or a method in the package
import packageName as pN