How do I write a parameter of a function if its a string in a statement?

Viewed 48

I'm trying to write a python function with some parameters that are strings in the statement.

def deleteElement(file, selector, value):
  with open(file) as f:
    soup = BeautifulSoup(f, 'html.parser')
    removeThis = soup.find('div', {selector : value}) ...

When I run the function, do I just type the values with quotes?

deleteElement('file.txt', 'class', 'main-div')

so that it would be interpreted as:

removeThis = soup.find('div', {'class' : 'main-div'})
1 Answers

That is exactly how you do it.

def function (var1, var2, var3):
    print (var1, var2, var3)

function("one", "two", "three")

output: 

>> one two three

From the above mentioned example of a simple function you can see that the function variables are just that, normal variables, as such should be defined as any other variable.

Related