-
Notifications
You must be signed in to change notification settings - Fork 0
/
string slicing and other function.py
120 lines (89 loc) · 3.14 KB
/
string slicing and other function.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
mystr = "virtual world"
decimal = 's.s.f.a.e'
digits = "12345"
# # String slicing
# 1. start argument
# staring index of string
# print(mystr[0:])
# 2. stop argument
# ending index of string
# print(mystr[:7])
# 3. step argument
# skipping index of string
# print(mystr[::2])
# string slicing refers to print perticular part of string
# print(mystr[0:7])
# if we left stop argument undefined it will be set to end of string
# print(mystr[0:])
# if we left start argument undefined it will be set to '0' means starting of the string
# print(mystr[:7])
# if we left both arguments undefined it will print the whole string
# print(mystr[:])
# if left step index undefined it will set to default 1
# print(mystr[::])
# negative arguments
# print(mystr[-5:-3])
# to reverse the order of string
# print(mystr[::-1])
# print(mystr[::-2])
# len function is used to find the length of string
# print(len(mystr)
# # Other Functions and Method
# 1. type function
# type function is used to get data type of any data
# print(type(mystr))
# 2. isalnum method
# isalnum function is used to check whelter the data is integer or not or whelter the data is alpha or not
# print(mystr.isalnum())
# 3. isalpha method
# isalpha method is used to check whelther the data is alpha or not
# print(mystr.isalpha())
# 4. endswith method
# endswith method is used to check whelther the data is ending with perticular syndex
# print(mystr.endswith('ld'))
# 5. count method
# count method is used to count perticular character of a string
# print(mystr.count('r'))
# 6. capitalize method
# capitalize method is used to make first letter capital
# print(mystr.capitalize())
# 7. find method
# find method is used to find perticular character in a string
# print(mystr.find('world'))
# 8. lower method
# lower method is used to write the whole string in small letters
# print(mystr.lower())
# 9. upper method
# upper method is used to write the whole string in capital letters
# print(mystr.upper())
# 10. replace method
# replace method is used to replace perticular character or word with another character or word
# print(mystr.replace("world", "environment"))
# 11. casefold method
# casefold method converts string into lower case
# print(mystr.casefold())
# 12. centre method
# centre method returns a centered string
# print(mystr.center(17, "*"))
# 13. encode method
# encode method returns an encoded version of the string
# print(mystr.encode())
# 14. expandtabs method
# expandtabs method sets the tab size of the string
# print(mystr.expandtabs(100))
# 15. format method
# format method formats specified values in a string
# print(mystr.format())
# 17. format_map method
# format_map method formats specified values in a string
# print(mystr.format_map())
# 18. isdecimal method
# isdecimal method returns true if all characters in the string are decimal
# print(mystr.isdecimal())
# print(decimal.isdecimal())
# 19. isidentifier method
# isidentifier method returns true if the string is an identifier
# print(mystr.isidentifier())
# 20 islower method
# islower method returns true if all characters in the string are lower case
# print(mystr.islower())