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

Резултати

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

Пребарај: #mygov

当前筛选 #mygov清除筛选
MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13060 · 19.01.2024 г., 06:26

Your voice matters in shaping Viksit Bharat @ 2047. Share your dreams for a thriving India on #MyGov. Join the journey at: https://innovateindia.mygov.in/viksitbharat2047/

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12690 · 10.05.2023 г., 07:41

Test your knowledge on India's journey towards Swaraj with the Swaraj Quiz Episode 39 on #MyGov. Visit https://quiz.mygov.in/quiz/swaraj-quiz-episode-39/ to learn about the inspiring leaders and events that shaped our nation's history.

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12657 · 02.05.2023 г., 06:33

Calling all aspiring tech entrepreneurs🧑‍💻🧑‍💻 Join the Chunauti 5.0 program by #MyGov and take a step towards a stronger and self-reliant India. Apply NOW and be a part of the innovative startup ecosystem. Visit: https://www.mygov.in/task/chunauti-50-%E2%80%93-call-application/

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12609 · 25.04.2023 г., 08:38

Oral health is crucial for overall well-being! Join the Oral Health campaign by #MyGov to spread awareness and promote healthy dental practices. Visit: https://mygov.in/campaigns/oral-health/?utm_source=mygov_campaign

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12562 · 18.04.2023 г., 10:40

Spread positivity and laughter with your creativity! Participate in the खुलकर जियो Khul Kar Muskurao meme contest on #MyGov and win exciting prizes. Visit: https://www.mygov.in/task/khulkar-jieo-khulkar-muskurao-meme-contest/

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12560 · 18.04.2023 г., 05:04

Congratulations to the winners of #MyGov's New India Quiz for March 🏆🏆 Your knowledge of India is impressive! Keep learning and exploring the diverse cultures and traditions of our incredible nation. Visit: https://blog.mygov.in/winner-announcement-blog-for-mygovs-new-india-quiz-march-month-mann-ki-baat/

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12557 · 17.04.2023 г., 08:35

Show your creativity and spread awareness about oral health through your writing skills! Participate in the Poem Writing Competition on #MyGov. Visit: https://www.mygov.in/task/poem-writing-competition-oral-health/

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12555 · 16.04.2023 г., 10:31

Lights, Camera, Smile! Showcase your filmmaking skills and spread positivity with 'खुलकर जियो Khul Kar Muskurao short film contest' on #MyGov. Visit https://www.mygov.in/task/khulkar-jieo-khulkar-muskurao-short-film-contest/ for more details

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12354 · 19.03.2023 г., 08:02

Capture the Beauty of Ladakh with your lens. Participate in Photography Contest on #MyGov Visit: https://ladakh.mygov.in/task/capture-beauty-ladakh-photography-contest

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12338 · 16.03.2023 г., 15:22

Capture the Beauty of Ladakh with your lens. Participate in Photography Contest on #MyGov Visit: https://ladakh.mygov.in/task/capture-beauty-ladakh-photography-contest

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12336 · 16.03.2023 г., 09:56

#MyGov now reaches the breathtaking landscapes of Ladakh to foster greater citizen engagement & empowerment Visit: ladakh.mygov.in

Hashtags

123•••78
ПретходнаСтраница 1 од 8Следна