How to split string by new line in Python

2 Answers

0 votes
s = 'python\njava\nc++\nc\nswift\nc#'
 
s = s.split('\n')
 
print(s)
 
 
 
'''
run:
 
['python', 'java', 'c++', 'c', 'swift', 'c#']
 
'''

 



answered Oct 26, 2020 by avibootz
0 votes
s = '''python
java
c++'''

s = s.split('\n')
 
print(s)
 
 
 
'''
run:
 
['python', 'java', 'c++']
 
'''

 



answered Oct 26, 2020 by avibootz

Related questions

2 answers 344 views
1 answer 287 views
1 answer 166 views
166 views asked Jul 31, 2023 by avibootz
2 answers 409 views
...