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 347 views
1 answer 290 views
1 answer 171 views
171 views asked Jul 31, 2023 by avibootz
2 answers 411 views
...