Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
numpy string operations | lstrip() function
Next article icon

numpy string operations | ljust() function

Last Updated : 05 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

numpy.core.defchararray.ljust(arr, width, fillchar=' ') is another function for doing string operations in numpy. It returns an array with the elements of arr left-justified in a string of length width. It fills remaining space of each array element using fillchr parameter. If fillchr is not passed then it fills remaining spaces with blank space.

Parameters:
arr : array_like of str or unicode.Input array.
width : The final width of the each string .
fillchar : The character to fill in remaining space.

Returns : Output array of str or unicode, depending on input type.

Code #1 :




# Python program explaining
# numpy.char.ljust() method 
  
# importing numpy 
import numpy as geek
  
# input array  
in_arr = geek.array(['Numpy', 'Python', 'Pandas'])
print ("Input array : ", in_arr) 
  
# setting the width of each string to 8
width = 8
  
# output array when fillchar is not passed
out_arr = geek.char.ljust(in_arr, width)
print ("Output left justified array: ", out_arr) 
 
 
Output:
  Input array :  ['Numpy' 'Python' 'Pandas']  Output left justified array:  ['Numpy   ' 'Python  ' 'Pandas  ']  

 

Code #2 :




# Python program explaining
# numpy.char.ljust() method 
  
# importing numpy 
import numpy as geek
  
# input array  
in_arr = geek.array(['Numpy', 'Python', 'Pandas'])
print ("Input array : ", in_arr) 
  
# setting the width of each string to 8
width = 8
  
# output array 
out_arr = geek.char.ljust(in_arr, width, fillchar ='*')
print ("Output left justified array: ", out_arr) 
 
 
Output:
  Input array :  ['Numpy' 'Python' 'Pandas']  Output left justified array:  ['Numpy***' 'Python**' 'Pandas**']  

 

Code #3 :




# Python program explaining
# numpy.char.ljust() method 
  
# importing numpy 
import numpy as geek
  
# input array  
in_arr = geek.array(['1', '11', '111'])
print ("Input array : ", in_arr)
  
# setting the width of each string to 5
width = 5
  
# output array
out_arr = geek.char.ljust(in_arr, width, fillchar ='-')
print ("Output left justified array: ", out_arr) 
 
 
Output:
  Input array :  ['1' '11' '111']  Output left justified array:  ['1----' '11---' '111--']  


Next Article
numpy string operations | lstrip() function
author
jana_sayantan
Improve
Article Tags :
  • Python
  • Python numpy-String Operation
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • numpy string operations | lstrip() function
    numpy.core.defchararray.lstrip(arr, chars=None) is another function for doing string operations in numpy. It returns a copy with the leading characters removed for each element in arr. Parameters: arr : array_like of str or unicode. char : [str or unicode, optional] the set of characters to be remov
    2 min read
  • Numpy - String Functions & Operations
    NumPy String functions belong to the numpy.char module and are designed to perform element-wise operations on arrays. These functions can help to handle and manipulate string data efficiently. Table of Content String OperationsString Information String Comparison In this article, we’ll explore the v
    5 min read
  • numpy string operations | less() function
    numpy.core.defchararray.less(arr1, arr2) is another function for doing string operations in NumPy. It checks the elements of two same shaped string arrays one by one and returns True if the elements of arr1 are less than the elements of arr2 i.e. arr1 < arr2 . Otherwise, it returns False. Paramet
    2 min read
  • numpy string operations | istitle() function
    numpy.core.defchararray.istitle(arr) function returns True for each element in the array if the element is a titlecased string and there is at least one character, it returns false otherwise. Parameters: arr : array_like of str or unicode Returns : [ndarray] Output array of bools. Code #1: # Python
    1 min read
  • numpy string operations | isdigit() function
    numpy.core.defchararray.isdigit(arr) function returns True for each element if all characters in the string are digits and there is at least one character; returns false otherwise. Parameters: arr : array_like of str or unicode. Returns : [ndarray] Output array of bools. Code #1 : # Python program e
    1 min read
  • numpy string operations | lower() function
    numpy.core.defchararray.lower(arr) function is used to return an array with the elements converted to lowercase. Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [ndarray] Output lowercased array of str or unicode, depending on input type. Code #1: # Python Program
    1 min read
  • numpy string operations | isalpha() function
    numpy.core.defchararray.isalpha(arr) function returns True for each element if all characters in the string are alphabetic and there is at least one character; returns false otherwise. Parameters: arr : array_like of str or unicode. Returns : [ndarray] Output array of bools. Code #1 : # Python progr
    1 min read
  • numpy string operations | isspace() function
    numpy.core.defchararray.isspace(arr) function returns true for each element if there are only whitespace characters in the string and there is at least one character.It returns false otherwise. Syntax: numpy.core.isspace(arr) Parameters: arr : array_like of str or unicode. Returns : [ndarray] Output
    2 min read
  • numpy string operations | less_equal() function
    numpy.core.defchararray.less_equal(arr1, arr2) is another function for doing string operations in numpy. It checks the elements of two same shaped string array one by one and returns True if the elements of arr1 are less than or equal to the elements of arr2 i.e. arr1 <= arr2 .Otherwise, it retur
    2 min read
  • numpy string operations | not_equal() function
    numpy.core.defchararray.not_equal(arr1, arr2) is another function for doing string operations in numpy. It checks the elements of two same shaped array one by one and returns True if they are not equal. Otherwise, it returns False. Parameters: arr1 : array_like of str or unicode. arr2 : array_like o
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences