TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #309 · 2 фев.

Метод строки split() разделяет строку на несколько строк по указанному символу >>> "a_b_c".split('_') ['a', 'b', 'c'] Можно указать максимальное количество разделений >>> "a_b_c".split('_', 1) ['a', 'b_c'] Или резать с другой стороны с помощью rsplit() (right split) >>> "a_b_c".rsplit('_', 1) ['a_b', 'c'] А что будет если оставить аргументы пустыми? >>> "a_b_c".split() ['a_b_c'] Получаем список с одним элементом, потому что по умолчанию используется пробельный символ. >>> "a b c".split() ['a', 'b', 'c'] То есть это равнозначно такому вызову? >>> "a b c".split(" ") ['a', 'b', 'c'] Кажется да, но нет! Давайте попробуем добавить пробелов между буквами >>> "a b c".split(" ") ['a', '', '', 'b', '', '', 'c'] И вот картина уже не так предсказуема 😕 А вот что будет по умолчанию >>> "a b c".split() ['a', 'b', 'c'] Всё снова красиво! 🤩 По умолчанию в качестве разделителя используется любой пробельный символ, будь то табуляция или новая строка. Включая несколько таких символов идущих подряд. А также игнорируются пробельные символы по краям строки. >>> "a\t b\n c ".split() ['a', 'b', 'c'] Аналогичный способ можно собрать с помощью регулярного выражения. Но пробелы по краям строки придется обрабатывать дополнительно. >>> import re >>> re.split(r"\s+", ' a b c '.strip()) ['a', 'b', 'c'] Здесь тоже можно указать количество разделений >>> re.split(r"\s+", 'a b c', 1) ['a', 'b c'] А что если мы хотим написать красиво, то есть split() без аргументов, но при этом указать количество разделений? В этом случае первым аргументом передаём None >>> "a\n b c".split(None, 1) ['a', 'b c'] Данный метод не учитывает строки с пробелами, взятые в кавычки 'a "b c" '.split() ['a', '"b', 'c"'] Но для таких случаев есть другие способы. #tricks#basic

Резултати

Пронајдени 8 слични објави

Пребарај: #allaboutbuses

当前筛选 #allaboutbuses清除筛选
SG MRT Updates

@sgmrt · Post #2230 · 22.01.2025 г., 03:44

Train services on the North-South, East-West, Circle & Thomson-East Coast Lines, and some bus services will be extended for commuters travelling late on the eve of Chinese New Year, 28 Jan (after midnight). See poster for more info.🧧#SMRT#AllAboutTrains#AllAboutBuseshttps://bit.ly/4g6JEzO - SMRT

SG MRT Updates

@sgmrt · Post #1947 · 31.05.2024 г., 02:09

Train services on the North-South, East-West, Circle & Thomson-East Coast Lines, and some bus services will be extended for commuters travelling late on the eve of Hari Raya Haji, 16 Jun 2024 (after midnight). Ref to the poster for more info. #SMRT#AllAboutTrains#AllAboutBuseshttps://bit.ly/4bWEkx9 - SMRT

SG MRT Updates

@sgmrt · Post #1902 · 04.04.2024 г., 02:29

Train services on North-South, East-West, Circle & Thomson-East Coast Lines, and some bus services will be extended for commuters travelling late on eve of Hari Raya Puasa, 9 Apr 2024 (after midnight). Ref to the poster for more info. #SMRT#AllAboutTrains#AllAboutBuseshttps://bit.ly/3vLtQRF - SMRT

SG MRT Updates

@sgmrt · Post #1864 · 11.12.2023 г., 09:05

Train services on the 🚆 North-South, East-West, Circle & Thomson-East Coast Lines, and some 🚍 bus services will be extended for commuters travelling late during the eve of Christmas and New Year. See the poster for more info. #SMRT#AllAboutTrains#AllAboutBuseshttps://bit.ly/3NjRnyE - SMRT

SG MRT Updates

@sgmrt · Post #1709 · 24.04.2023 г., 10:45

Train services on the 🚊 North-South, East-West, Circle & Thomson-East Coast Lines, and some 🚍 bus services will be extended for commuters travelling late on the eve of Labour Day, 30 April 2023. Refer to the poster for more info. 👀#SMRT#AllAboutTrains#AllAboutBuseshttps://bit.ly/41RQZwf - SMRT

SG MRT Updates

@sgmrt · Post #1583 · 05.01.2023 г., 05:16

Train services on the 🚆 North-South, East-West, Circle & Thomson-East Coast Lines, and some 🚍 bus services will be extended for commuters travelling late on the eve of Chinese New Year. 🧧 Refer to the poster for more info! 👀#SMRT#AllAboutTrains#AllAboutBuseshttps://bit.ly/3igIWI8 - SMRT

SG MRT Updates

@sgmrt · Post #1563 · 09.12.2022 г., 09:28

Train services on the 🚆 North-South, East-West, Circle & Thomson-East Coast Lines, and some 🚍 bus services will be extended for commuters travelling late during the eve of Christmas and New Year. Refer to the poster for more info!🥳#SMRT#AllAboutTrains#AllAboutBuseshttps://bit.ly/3uDtXe8 - SMRT