-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringBuilt.py
42 lines (32 loc) · 1.39 KB
/
StringBuilt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# String built-in functions example
# 1. len() - returns the length of a string
string = "vishwajeet Kamble!"
length = len(string)
print("Length of the string:", length)
# 2. upper() - converts a string to uppercase
uppercase = string.upper()
print("Uppercase string:", uppercase)
# 3. lower() - converts a string to lowercase
lowercase = string.lower()
print("Lowercase string:", lowercase)
# 4. capitalize() - capitalizes the first character of a string
capitalized = string.capitalize()
print("Capitalized string:", capitalized)
# 5. count() - returns the number of occurrences of a substring in a string
count = string.count("e")
print("Count of 'o':", count)
# 6. find() - returns the index of the first occurrence of a substring in a string
index = string.find("Kale")
print("Index of 'World':", index)
# 7. replace() - replaces all occurrences of a substring with another substring
replaced = string.replace("Dog", "Cat")
print("Replaced string:", replaced)
# 8. split() - splits a string into a list of substrings based on a delimiter
split_list = string.split(",")
print("Split list:", split_list)
# 9. isalpha() - checks if all characters in a string are alphabetic
is_alpha = string.isalpha()
print("Is alphabetic:", is_alpha)
# 10. isnumeric() - checks if all characters in a string are numeric
is_numeric = string.isnumeric()
print("Is numeric:", is_numeric)