#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

What are the major numpy string methods in python?
Description

To explore the string methods in numpy

Input

Sample string.

Output

Output from above mentioned constructor of numpy.

Methods

ceneter()
capitalize()
lower()
upper()
split()
encode()
decode()

Process

process:

   Import numpy library.

   Declare the sample string.

  Pass it to the appropriate constructor from numpy.

Sapmle Code

#import libraries
import numpy as np

#Sample string
sample_string = ‘hello python’

#center method
print(“Center method”)
print(np.char.center(sample_string, 20,fillchar = ‘*’))
print(“\n”)

#Capitalize method
print(“Capitalize method”)
print(np.char.capitalize(sample_string))
print(“\n”)

#title method
print(“title method”)
print(np.char.title(sample_string))
print(“\n”)

#lower method
print(“lower method”)
print(np.char.lower(sample_string))
print(“\n”)

#Upper method
print(“Upper method”)
print(np.char.upper(sample_string))
print(“\n”)

#split method
print(“split method”)
print(np.char.split (sample_string, sep = ‘,’))
print(“\n”)

#encode method
print(“encode method”)
e = np.char.encode(sample_string, ‘cp500′)
print(e,”\n”)

#decode metod
print(“decode method”)
print(np.char.decode(e,’cp500’))

Screenshots