Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use split and splitlines

Shulou Source: shulou.com Published: 2022-06-01 11:31:19 09月11日 Update

This article mainly explains "how to use split and splitlines". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use split and splitlines".

When using python's spilt to split a string, if you do not set the delimiter, it will be separated by empty characters by default. However, it is strange that the results of split () and split ('') are not the same word = 'hello world'.

Print (word.split ()) # ['hello',' world']

Print (word.split ('')) # ['hello',' world']

There is a similar situation in the splitlines function word = 'this s a line\ n'

Print (word.splitlines ()) # ['this s a line']

Print (word.split ('\ n')) # ['this s a line',']

In view of the split function is a string of more important functions, you should understand its strange behavior thank you for reading, the above is the "split and splitlines how to use" the content, after the study of this article, I believe we have a deeper understanding of how to use split and splitlines, the specific use of the situation also need to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Functions learning content characters strings same weird important delimiters that is ideas situations articles more knowledge knowledge points empty characters articles results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology Docker Redmi Microsoft