Description

len() method in python

len() method/function is used for calculate the length of string in python.

a = "Python"
print(len(a))

Output:

6

upper() method in python

upper() method returns the string in uppercase.

a = "pYtHOn"
print(a.upper())

Output:

PYTHON

lower() method in Python

lower() method returns the string in lowercase.

a = "pYtHOn"
print(a.lower())

Output:

python

strip() method in Python.

strip() method removes any whitespace from the beginning or the end.

a = "     Welcome Python World   "
print(a.strip())

Output:

Welcome Python World

replace string method in python.

replace() method replaces a string with another string.

a = "Hello, World"
print(a.replace("H", "T"))

Output:

Tello, World

split() method in python.

split() methods splits the string into substrings if it finds instances of the separator.

a = "Python"
print(a.split("t"))

Output:

['Py', 'hon']

capitalize() string method in python.

capitalize() converts the first character to uppercase.

a = "hello! how are you?"
print(a.capitalize())

Output:

Hello! how are you?

casefold() string method in Python.

casefold() method converts string into lower case.

a = "pYthON"
print(a.casefold())

Output:

python

center() string method in python.

center() method returns a centered string.

a = "python"
print(a.center(30))

Output:

            python

encode() string method in Python.

encode() method return an encoded version of the string.

a = "python is a very beautiful language"
print(a.encode())

Output:

b'python is a very beautiful language'

endswith() string method in Python.

endswith() method returns true if the string ends with the specified value.

a = "Hello Python"
print(a.endswith("n"))

Output:

True

 

expandtabs() string method in python.

expandtabs() method set the tab size of the string.

a = "H\te\tl\tl\to\t \tP\ty\tt\th\to\tn"
print(a.expandtabs(2))

Output:

H e l l o   P y t h o n

find() string method in python.

find() method() searched the string for a specified value and returns the position of where it was found.

a = "Hello Python"
print(a.find("P"))

Output:

6

format() string method in Python.

format() method specified values in a string.

a = "My Age is {age}"
print(a.format(age = 22))

Output:

My Age is 22

format_map() string method in Python.

format_map() method specifed values in a string.

n = {'n1': 'John', 'n2': 'Doy'}
print("{n1} is a best friend of {n2}".format_map(n))

Output:

John is a best friend of Doy

index() string method in Python.

index() method searches the string for a specifed value and returns the position of the where it was found.

t = "Welcome, All Happy Coders!"
i = t.index("All")
print(i)

Output:

9

isalnum() string method in Python.

isalnum() method returns true if all characters in the string are alphanumeric.

s = "789qwerty928"
print(s.isalnum()) # Returns True

s = "#4%q"
print(s.isalnum()) # Returns False

Output:

True
False

isalpha() string method in Python.

isalpha() method returns true if all characters in the string are the alphabet.

s = "String"
print(s.isalpha())

Output:

True

isdecimal() string method in Python.

isdecimal() method retruns true if all characters in the string are decimals.

s = "8268382"
print(s.isdecimal())

Output:

True

isdigit() string method in Python.

isdigit() method retruns true if all characters in the string are digits.

s = "826"
print(s.isdigit())

Output:

True

isidentifier() string method in Python.

isidentifier() method returns True if the string is an identifier.

st = "De_mo78"
print(st.isidentifier())

Output:

True

Comments

Login is mandatory to comment Please login

Recommended Posts

Operators based Exercise 1 in Python Programming language.

All operators used for better understanding the python operators.

Sets in Python | Perform Set methods

A Set is an unordered collection data type which does not contain duplicates elements. A set is iterable and mutable data type.

Conditional Statement If elif else statement in Python

Like some situation comes in our real life in which we have to take some decision as to what we have to do next.

Everything about of Loops in Python | For loop | While loop | Nested Loop

A loop is used for iterate the sequence. It is used to iterate List, String, Dictionary, Tuple. Iterating over a sequence is called traversal.

Function | Docstring | Lambda | Kwargs in Python

In Python programming, a function is a block of statements that makes our code readable. If we do that function in the program, then we do not have to write the same statement of code again and again.

What is Python? How Python is interpreted? What are the tools that help to find bugs or perform static analysis? What are Python Decorators?

Python Program is a gerneral purpose of high level, intereted, interative and object-oriented scription programming language developed by Guido Van Rossum in  1991.