batman_special
batman_special

Reputation: 125

replace single quotes with double quotes for string output

I have a function databricks written in pyspark which accepts to parameters and and the values passed to the function at as below: values as below

stringa = "XYZ_ABC"
stringb = "ab"

function is as below

def pos(stringa,stringb):
    if stringb in stringa:
      return stringa
    else:
        return stringa    
  ab = pos(stringa,stringb)

the above fuction returns me an output as 'XYZ_ABC' however the expected output is "XYZ_ABC"

Upvotes: -1

Views: 413

Answers (3)

Mark Ransom
Mark Ransom

Reputation: 308130

The string doesn't actually contain the quotes, they're just printed that way because the console displays a variable the same as print(repr(ab)). If you print(ab) you'll see the difference.

If you want quotes in the actual string you'll need to add them yourself, and you can add whichever style you like.

ab = '"' + pos(stringa,stringb) + '"'

Upvotes: 1

Dheeraj Kumar Y
Dheeraj Kumar Y

Reputation: 36

String "XYZ_ABC" or """XYZ_ABC""" or 'XYZ_ABC' or '''XYZ_ABC''' are same.

If you still want to have output on console in double-quotes use this print("""+ab+""")

Upvotes: 1

josepdecid
josepdecid

Reputation: 1847

There is no difference between using single or double-quoted strings. Both representations can be used interchangeably, so it has no sense to try to move from single to double-quotes.

If you write a double-quoted string in the console, you will see that the result is shown single-quoted.

>>> "asd"
'asd'

Upvotes: 0

Related Questions