-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrs.py
More file actions
56 lines (42 loc) · 1.02 KB
/
Copy pathstrs.py
File metadata and controls
56 lines (42 loc) · 1.02 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# my_string = 'Hello'
# print(my_string)
# my_string = "Hello"
# print(my_string)
#
my_string = '''Hello'''
print(my_string)
#
# triple quotes string can extend multiple lines
my_string = """Hello, someone please
help me, I'm stuck in this computer"""
print(my_string)
str = 'programiz'
print('str = ', str)
#first character
print('str[0] = ', str[0])
#last character
print('str[-1] = ', str[-1])
#slicing 2nd to 5th character
print('str[1:5] = ', str[1:5])
#slicing 6th to 2nd last character
print('str[5:-2] = ', str[5:-2])
#immutabliity (wtf is that huh)
my_string = 'applesauce or something idk'
my_string[5] = 't'
# oh no mr armani I broke the program
# let's try this instead
del my_string[1]
#look at what you've done
# Python String Operations
str1 = 'Hello'
str2 ='World!'
# using +
print('str1 + str2 = ', str1 + str2)
# using *
print('str1 * 3 =', str1 * 3)
#iteration (we'll get into this soon)
count = 0
for letter in 'Hello World':
if(letter == 'l'):
count += 1
print(count,'letters found')