-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
56 lines (45 loc) · 984 Bytes
/
function.py
File metadata and controls
56 lines (45 loc) · 984 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
49
50
51
52
53
54
55
56
#%% Change working directory from the workspace root to the ipynb file location. Turn this addition off with the DataScience.changeDirOnImportExport setting
import os
try:
os.chdir(os.path.join(os.getcwd(), 'learning_note\python_code'))
print(os.getcwd())
except:
pass
#%%
'''计算一段字符串长度'''
s1 = "hello world"
length = 0
for i in s1:
length = length+1
#每次循环增加一个数'''
print(length)
#打印出字符串长度数值'''
#%%
s2 = "hell eva"
length = 0
for i in s2:
length = length+1
print(length)
#%%
print(len(s1))
print(len(s2))
#%%
def mylen():
s1 = "hello world"
"""计算s1的长度"""
length = 0
for i in s1:
length = length+1
return length
#%%
str_len = mylen()
print('str_len : %s'%str_len)
#%%
def mylen(s1):
"""计算s1的长度"""
length = 0
for i in s1:
length = length+1
return length
str_len = mylen("你好世界,我是新手!")
print('str_len : %s'%str_len)