String functions in Python


String functions in Python
String functions in Python


What is a string in python? 

String Function is used to perform operations and manipulate strings.

some of the functions are listed below.

1.len() function

This function returns the length of string.

example:

 len("karan") ----> It returns 5

2. string.endswith("an")

This function is used to find the variable string end with "an"

3. string.count("c")

This function counts the total number of accurance of any characters in the string 

4. string.capitalize()

This function capitalize first character of a string

5. string. find(word)

This function finds the word in the string and returns the first occurrence of that word in a string

6. string.replace(oldword,newword)

This function replaces old word to new word in the entire strings

Python is made of several built-in functions associated with the string data type. These functions modify and manipulate strings. 

Python Built-in functions are those that are defined in the Python programming language and are readily available for us to use.

These are the example of string method which returns boolean values

str.isspace() string consists of only whitespace characters

str.istitle() string is in title case

str.isupper() string’s alphabetic characters are all upper case

str.islower() string’s alphabetic characters are all lower case

str.isnumeric() string consist numeric characters


String functions in Python
String functions in Python

output:

String functions in Python
String functions in Python


Python string Methods are listed below:


rstrip()

        It Returns a right trim version of the string

split()

        It  Splits the string at the specified separator, and returns a list

splitlines() 

        It    Splits the string at line breaks and returns a list

startswith()

        It  Returns true if the string starts with the specified value

strip()

        It  Returns a trimmed version of the string

swapcase()

It Swaps cases, lower case becomes upper case and vice versa

title()  

        It Converts the first character of each word to upper case

translate()

It Returns a translated string

upper()

It Converts a string into the upper case

zfill()

It Fills the string with a specified number of 0 values at the beginning

format()

It Formats specified values in a string

format_map()

It Formats specified values in a string

index()

It Searches the string for a specified value and returns the position of where it was found

isalnum()

It returns True if all characters in the string are alphanumeric

isalpha()

It returns True if all characters in the string are in the alphabet

isdecimal()

It returns True if all characters in the string is decimals

isdigit()

It returns True if all characters in the string is digits

isidentifier()

It returns True if the string is an identifier

islower()

It returns True if all characters in the string are lower case

isnumeric()

It returns True if all characters in the string are numeric

isprintable()

It returns True if all characters in the string are printable

isspace()

It returns True if all characters in the string are whitespaces

istitle()

It  returns True if the string follows the rules of a title

isupper()

It returns True if all characters in the string are upper case

join()

It Joins the elements of an iterable to the end of the string

ljust()

It  Returns a left-justified version of the string

lower()

It  Converts a string into lower case

lstrip()

It Returns a left trim version of the string

maketrans()

It Returns a translation table to be used in translations

replace()

It Returns a string where a specified value is replaced with a specified value

rindex()

        It Searches the string for a specified value.

rsplit()

      It Splits the string at the specified separator.




Read More: Uses of samba server and  key features of the samba server

Read More: Nitrux 1.5.1 is released with  KDE Plasma Desktop

Read More: Redhat  troubleshooting interview questions




Previous
Next Post »