+ 3
You need to have more than one value argument in the print statement before it works, like this......
print(var_1, var_2, sep="_")
+ 2
Naina Kapoor That's because you haven't created a var_2 with a value, but you can also just write...
print(var_1, var_1, sep="_")
+ 2
Naina Kapoor
you must have more than 1 item to print, otherwise there is nothing to separate.
print(1,2,3,4, sep='_')
in your example, you are only printing var1
+ 2
Naina Kapoor
you can still use sep if you are just printing the result for a camel to snake conversion.
def c2s(s):
n=0
res=[]
for i,e in enumerate(s):
if e.isupper():
res.append(s[n:i].lower())
n = i
res.append(s[n:].lower())
print(*res, sep='_')
var = input().strip()
c2s(var)
s1 = 'weNeedToConvertToSnakeCase'
c2s(s1)
+ 1
We cannot see others code coach solution using the links.
+ 1
Naina Kapoor
sep will not work like that
You have to use formatter like this
f"_{var}"
But you have to iterate string and check if a character is in upper case then use formatter to replace that character with _
+ 1
Look at the difference:
print("hello!, sep="_" ) #hello
print("hello", "world", sep="_") #hello_world
+ 1
Fareedah Olusunmade
Tapha Sarr
Do not spam
+ 1
Naina Kapoor
it's called slicing . it works for lists and strings to chop up parts you need.