Exercise 6

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Ex. No.

: 6 Implementing NumPy string functions -add, multiply, center, split, join,


capitalize, lower

import numpy as np

print("Concatenating two string arrays:")

print(np.char.add(['I'], [' am'] ))

print(np.char.add(['I'], [' am', ' man'] ))

print(np.char.add(['welcome','Hi'], [' to class', ' read python'] ))

print("Printing a string multiple times:")  

print(np.char.multiply("hello ",3))  

print("Padding the string through left and right with the fill char *");  

#np.char.center(string, width, fillchar)  

print(np.char.center(“boy", 5, '*'))  

print("Capitalizing the string using capitalize()...")  

print(np.char.capitalize("welcome to noida"))  

print("Converting string into title cased version...")  

print(np.char.title("welcome to noida"))  

print("Converting all the characters of the string into lowercase...")  

print(np.char.lower("WELCOME TO NOIDA"))  

print("Converting all the characters of the string into uppercase...")  

print(np.char.upper("Welcome To Noida"))  

a=np.array(['geeks', 'for', 'geeks'])

# counting a substring

print(np.char.count(a,'geek'))

 # counting a substring

print(np.char.count(a, 'fo'))

a=np.array(['geeks', 'for', 'geeks'])

 # counting a substring

print(np.char.rfind(a,'geek'))

 # counting a substring

print(np.char.rfind(a, 'fo'))

You might also like