• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Python » Python String splitlines() Method
Next →
← Prev

Python String splitlines() Method

By Dinesh Thakur

The method splitlines() returns a list with all the lines in string, optionally including the line breaks (if num is supplied and is true)

The syntax of the method is: str.splitlines( num = string.count('\n'))

Key Points :

• When the string is interrupted, various lines are combined into a list returned by this function. We may then assume that it returns a split lines array.
• The numerous line break forms are \n(newline character), \r(carriage return), \r\n(carriage back+new line).

We’ll be covering the following topics in this tutorial:

  • splitlines() Parameters
  • Return Value from splitlines()
  • Supported Splitlines() method line boundary characters:

splitlines() Parameters

Splitlines() takes up to 1 parameter.

• An optional parameter that may take one of two values: true or false.

The line breaks are included in the resulting list when this parameter is set to True. It may be numerical, which defines a line break position or some Unicode characters, such as \n, \r, \r\n, etc., which serve as a string boundary.

Return Value from splitlines()

This method returns a list consisting of the main string lines which are broken down on the basis of the boundaries characters in the main string.

Below is the python program to demonstrate the splitlines() function:

str = "Q1 Delhi\nQ2 Mumbai\n\nQ3 Pune";
print (str.splitlines( ))
print (str.splitlines( 0 ))
print (str.splitlines( 5 ))

When we run above the program, the outcome is as follows:

[‘Q1 Delhi’, ‘Q2 Mumbai’, ”, ‘Q3 Pune’]
[‘Q1 Delhi’, ‘Q2 Mumbai’, ”, ‘Q3 Pune’]
[‘Q1 Delhi\n’, ‘Q2 Mumbai\n’, ‘\n’, ‘Q3 Pune’]

Supported Splitlines() method line boundary characters:

The splitlines() method split lines on the following line boundary characters:

RepresentationDescription
\nLine Feed
\rCarriage Return
\r\nCarriage Return + Line Feed
\v or \x0bLine Tabulation
\f or \x0cForm Feed
\x1cFile Separator
\x1dGroup Separator
\x1eRecord Separator
\x85Next Line (C1 Control Code)
\u2028Line Separator
\u2029Paragraph Separator

Below are several other functions that we can use to work with string in Python 3

capitalize()
center()
count()
decode()
encode()
endswith()
expandtabs()
find()
index()
isalnum()

isalpha()

isdecimal()
isdigit()
islower()
isnumeric()
isspace()
istitle()
isupper()
join()
ljust()

lower()

lstrip()
maketrans()
max()
min()
replace()
rfind()
rindex()
rjust()
rstrip()

split()

splitlines()
startswith()
strip()
swapcase()
title()
translate()
upper()
zfill()

You’ll also like:

  1. Python String strip() Method
  2. Python String rindex () Method
  3. Python String maketrans() Method
  4. Python String expandtabs() Method
  5. Python String join() Method
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Python

Python Tutorials

  • Python - Home
  • Python - Features
  • Python - Installation
  • Python - Hello World
  • Python - Operators Types
  • Python - Data Types
  • Python - Variable Type
  • Python - Switch Case
  • Python - Line Structure
  • Python - String Variables
  • Python - Condition Statement
  • Python - if else Statement
  • Python - for-loop
  • Python - while loop
  • Python - Command Line
  • Python - Regular Expression

Python Collections Data Types

  • Python - List
  • Python - Sets
  • Python - Tuples
  • Python - Dictionary

Python Functions

  • Python - Functions
  • Python - String Functions
  • Python - Lambda Function
  • Python - map() Function

Python Object Oriented

  • Python - Oops Concepts
  • Python - File Handling
  • Python - Exception Handling
  • Python - Multithreading
  • Python - File I/O

Python Data Structure

  • Python - Linked List
  • Python - Bubble Sort
  • Python - Selection Sort
  • Python - Linear Search
  • Python - Binary Search

Python Programs

  • Python - Armstrong Number
  • Python - Leap Year Program
  • Python - Fibonacci Series
  • Python - Factorial Program

Other Links

  • Python - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW