-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_ex1.py
More file actions
67 lines (49 loc) · 1.43 KB
/
python_ex1.py
File metadata and controls
67 lines (49 loc) · 1.43 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
57
58
59
60
61
62
63
64
65
66
67
classic='The Great Gatsby'
print("문자열 내 문자 개수 :", len(classic)) #16 반환
book=[classic, 'Le Petit Prince', 'Gut Gegen Nordwind', 'Principles', 'The Beginners', 'Money Ball']
print("배열 내 원소 개수 :", len(book)) #6 반환
book.append('The Big Short')
print("배열 내 원소 개수 :", len(book)) #7 반환
fp=open('test.txt', 'w', encoding='utf-8')
for title in book:
fp.writelines(title+'\n')
fp.close()
fp=open('test.txt', 'r', encoding='utf-8')
book_list=[]
for line in fp.readlines():
line = line.strip('\n')
book_list.append(line)
print(book_list)
wow = '---Wow! You\'re the best student ever!---'
print(wow.strip('-'))
print(wow.strip('-').split(' '))
print('tacocat'.replace('c', 'r'))
even_list = [x*x for x in range(10)]
print(even_list)
even_list = []
for x in range(10):
if x%2==0:
even_list.append(x)
print(even_list)
temp_list = ['My ', '', 'textbook ', '', '', 'is', 'quite', '', 'old']
print(temp_list)
temp_list = [tmp+'\n' for tmp in temp_list if tmp]
print(temp_list)
word_list = []
for word in temp_list:
if word:
word_list.append(word)
print(word_list)
'''
temp_list = []
temp_list = [' ', '\n', 'espresso', ' ', '', 'strawberry juice ', '', 'cafe mocha', '', '\n']
print(temp_list)
temp_list = [tmp for tmp in temp_list if tmp]
print(temp_list)
tmp = ''
for line in temp_list:
tmp += line
tmp = tmp.strip(' ')
tmp = tmp.replace('\n', '')
print(tmp)
'''