Home > Net >  Split function leaving out characters after underscore
Split function leaving out characters after underscore

Time:02-11

# Multiline string
sqlVals = """
behaviorResult
Hobbies_Interest_Etc
""" 

cSharpValues = """
Getting_to_WorkSchool
hobbies_interest_etc
"""

splitSqlVals = sqlVals.split()
splitCSharpVals = cSharpValues.split()

print(splitSqlVals)
print(splitCSharpVals)

returns:

splitSqlVals:  ['behaviorResult', 'Hobbies_Interest_Etc']
splitCSharpVals:  ['Getting_to_WorkSchool', 'hobbies_interest_']

The version of Python is 3.9.10. I'm not understanding why "hobbies_interest_etc" after the split call is not "hobbies_interest_etc" and instead is "hobbies_interest_", but "Hobbies_Interest_Etc" is split as expected.

CodePudding user response:

you have 2 options:

  1. splitlines():
cSharpValues.splitlines()
  1. split("\n"):
splitCSharpVals = cSharpValues.split("\n")

CodePudding user response:

The issue is that there is a bug in the online compiler I was using.

I have contacted the relevant authorities

  • Related