-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrings.py
55 lines (35 loc) · 892 Bytes
/
strings.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
# Strings surrownded by single quotes or double quotes
# name = 'Heba'
# age = 18
# Concatenate
# print('My Name Is ' + name + ' And My Age is ' + str(age) + ' years old!')
# String Formating
# print('My Name Is {name} And My Age is {age} years old!'.format(name = name, age = age))
# F- Strings
# print(f'My Name Is {name} And My Age is {age} years old!')
# string methods
phrase = 'hello world'
# # capitalize
# print(phrase.capitalize())
# # uppercase
# print(phrase.upper())
# # lowercase
# print(phrase.lower())
# # swapcase
# print(phrase.swapcase())
# length
# print(len(phrase))
# # replace
# print(phrase.replace('world', 'Heba'))
# count
# substring = 'h'
# print(phrase.count(substring))
# start with
# print(phrase.startswith('hell'))
# end with
# print(phrase.endswith('ld'))
#split
# print(phrase.split())
#find
# print(phrase.find('l'))
# print(phrase[1])