top of page

Python Assignment Help - Deal With Python String Method | How To Implement Python String Methods?

Python is collection of different types of String Methods which help to deal string easily.




Important Python String Method


  • strip(), rstrip(). lstrip()

  • split()

  • count()

  • format()

  • find()

  • index()

  • islower(), isupper()

  • lower(), upper()

  • replace()


strip():

The strip() removes characters from both left and right based on the argument (a string specifying the set of characters to be removed).


Syntax:

string.strip(['character'])

Ex.

string = ' naveen kumar rajput '

# white space remove

print(string.strip())

# remove nav from string at start

print(string.strip('nav'))



split():

The split() method breaks up a string at the specified separator and returns a list of strings.


The syntax of split() is :


str.split(separator[,maxsplit])

Ex.

text= "naveen kumar"


# split at space found

print(text.split())


output:

['naveen', 'kumar']


name = 'naveen, kumar, rajput'

# split at (,) found

print(text.split(','))


output:

['naveen', 'kumar', 'rajput']



format() in python:

The string format() method formats the given string into a nicer output in Python.

format() method takes any number of parameters. But, is divided into two types of parameters:

Positional parameters - list of parameters that can be accessed with index of parameter inside curly braces {index}

Keyword parameters - list of parameters of type key=value, that can be accessed with key of parameter inside curly braces {key}


Ex.

Basic format() Examples:


print("Hello {}, your balance is {}.".format("naveen", 16.8))

print("Hello {name}, your balance is {blc}.".format(name="naveen", blc=16.8))

print("The float number is:{:f}".format(123.456))

print("The float number is:{:3f}".format(123.456))


If you want to find any problem with python programming or project, contact at given link which is given below and find your problem solution within few hours.


Link- Contact here to find solution or visit official website


Comentários


bottom of page