Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Splitting the Lines | String Methods
String Manipulation in Python

bookSplitting the Lines

If we are working with text, most likely it will contain more than 1 line. And it would be great if we could split such string into lines.

One way to do it is to use .split method from the previous chapter with escape character \n as an argument (this one makes a line break). But Python provides us with a special function, that makes it - .splitlines. This function has only one optional argument keeplinebreaks (bool) that specifies if the line breaks should be included (if True), or shouldn't (if False, by default).

Tâche

Swipe to start coding

Given multiline string zen with the first 6 principles The Zen of Python, by Tim Peters. Split this string by lines (without printing the escape characters).

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 5
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Résumer ce chapitre

Expliquer le code dans file

Expliquer pourquoi file ne résout pas la tâche

close

Awesome!

Completion rate improved to 4.35

bookSplitting the Lines

Glissez pour afficher le menu

If we are working with text, most likely it will contain more than 1 line. And it would be great if we could split such string into lines.

One way to do it is to use .split method from the previous chapter with escape character \n as an argument (this one makes a line break). But Python provides us with a special function, that makes it - .splitlines. This function has only one optional argument keeplinebreaks (bool) that specifies if the line breaks should be included (if True), or shouldn't (if False, by default).

Tâche

Swipe to start coding

Given multiline string zen with the first 6 principles The Zen of Python, by Tim Peters. Split this string by lines (without printing the escape characters).

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

close

Awesome!

Completion rate improved to 4.35
Section 2. Chapitre 5
single

single

some-alt