0% found this document useful (0 votes)
5 views

String_handling_function_python

The document provides a series of Python string manipulation examples, demonstrating various functions such as length, searching, case conversion, and formatting. It includes methods like `find`, `isalnum`, `isalpha`, `isdigit`, `replace`, `split`, `strip`, and others to manipulate and analyze strings. Each example is accompanied by a print statement to display the output of the operations performed.

Uploaded by

nafeesathsamuda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

String_handling_function_python

The document provides a series of Python string manipulation examples, demonstrating various functions such as length, searching, case conversion, and formatting. It includes methods like `find`, `isalnum`, `isalpha`, `isdigit`, `replace`, `split`, `strip`, and others to manipulate and analyze strings. Each example is accompanied by a print statement to display the output of the operations performed.

Uploaded by

nafeesathsamuda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

#length of string
print(len("Hello World!"))

2. #find the string


print("Hello World!".find("World"))
print("Hello World!".find("Hey"))

3. #isalnum - check alphanumeric present or not


print("Nidhyathi".isalnum())
print("Nidhyathi24".isalnum())
print("Nidhyathi#24".isalnum())

4. #isalpha - check alphabets present or not


print("Nidhyathi".isalpha())
print("Nidhyathi234".isalpha())

5. #isdigit - check digits present or not


print("241".isdigit())
print("fnc123".isdigit())

6. #replaces another word in a string


print("I am learning java".replace("java","python"))

7. #split is used to cut and make a list (seperator)


print("Hey.How are you?".split("."))
print("Hey how are you doing ?".split(" "))

8. #strip removes spaces at the beginning and at the end


print(" Hello World! ".strip())
print(len(" Hello World! ".strip()))

9. #lstrip removes spaces at the beginning


print(" Hello World! ".lstrip())
print(len(" Hello World! ".lstrip()))

10. #rstrip removes spaces at the beginning


print(" Hello World! ".rstrip())
print(len(" Hello World! ".rstrip()))

11. #upper - converts to upper case


print("Hello World!".upper())

12. #lower - converts to lower case


print("Hello World!".lower())

13. #isupper - verifies if string is in upper case


print("hello world!".isupper())
print("HELLO WORLD!".isupper())

14. #islower - verifies if string is lower case


print("hello world!".islower())
print("HELLO WORLD!".islower())

15. #f string - used to insert values in a string from previous part of function
name = "Nidhyathi"
print(f"Hey, my name is {name}")

16. #format - formats the specified value(s) and insert them inside the string's
placeholder
print("Hey, my name is {name}".format(name = "Nidhyathi"))

txt = "For only {price:.2f} dollars!"


print(txt.format(price = 49))

#Use "<" to left-align the value:

txt = "We have {:<8} chickens."


print(txt.format(49))

#Use ">" to right-align the value:

txt = "We have {:>8} chickens."


print(txt.format(49))

#Use "^" to center-align the value:


txt = "We have {:^8} chickens."
print(txt.format(49))

17. #index returns position of string


print("Hello World!".index("World"))
print("Hello World!".index("Hey"))

18. #ORD returns Unicode of character


x = ord("h")
print(x) #104

You might also like