-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilt in string functions.py
More file actions
40 lines (34 loc) · 1.91 KB
/
built in string functions.py
File metadata and controls
40 lines (34 loc) · 1.91 KB
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
#Built in string Functions
str1 = input('Enter any input string: ')
print('The length of the string is: ', len(str1))
print('The string in uppercase is: ', str1.upper())
print('The string in titlecase is: ', str1.title())
print('The string in lowercase is: ', str1.lower())
print('The string in swapcase is: ', str1.swapcase())
print('The string in capitalize is: ', str1.capitalize())
print('Whether the string is alphanumeric: ', str1.isalnum())
print('Whether the string is digit: ', str1.isdigit())
print('Whether the string is alpha: ', str1.isalpha())
print('Whether the string is lower: ', str1.islower())
print('Whether the string is upper: ', str1.isupper())
print('Whether the string is title: ', str1.istitle())
print('Whether the string is space: ', str1.isspace())
print('Max character in the string is: ', max(str1))
print('Min character in the string is: ', min(str1))
print('The string in center is: \n ', str1.center(50, '*'))
char = input('Enter the character to be count: ')
print('The character count is: ', str1.count(char))
char = input('Enter the character to be found using find function: ')
print('The character found at index: ', str1.find(char))
char = input('Enter the character to be found using index function: ')
print('The character rfound at index: ', str1.index(char))
str2 = input('Enter the string to be replaced: ')
str3 = input('Enter the string to be replaced with: ')
print('The string after replacement is: ', str1.replace(str2, str3))
print('The string after splitting is :', str1.split())
str4 = tuple(input('Enter the string to be joined: '))
print('The string after joining is: ', str1.join(str4))
end_with = input('Enter the string to be checked at the end: ')
print('Whether the string ends with the given string: ', str1.endswith(end_with))
start_with = input('Enter the string to be checked at the start: ')
print('Whether the string starts with the given string: ', str1.startswith(start_with))