-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrings.py
More file actions
48 lines (40 loc) · 796 Bytes
/
Copy pathstrings.py
File metadata and controls
48 lines (40 loc) · 796 Bytes
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
# loops.py
myString = ""
print(type(myString))
myString = 'single quotes'
# String literals
print("""\
Usage: stuff
-h help
""")
print('''hello
world''')
long_string = ('long '
'string')
print(long_string)
# Raw Strings
print('hello\nworld')
print(r'hello\nworld')
# Common String Methods in Python
print("axbxcx".count('x'))
print("axbxcx".find("x"))
print("HELLO".lower())
print("hello".upper())
print("hola".replace('h', 'b'))
print(" hello ".strip())
# String Indexes
a = "string"
print(a[1:3]) # indexing is 0-based, 3 is non-inclusive
print(a[:-1])
word = 'Python'
print(word[0])
print(word[5])
print(word[-1])
print(word[-6])
print(word[0:2]) # slicing
print(word[2:5])
print(word[:2])
print(word[2:])
print(word[4:42])
print(word[42:])
# lists.py