这道题什么意思啊,没看懂,请帮我讲一下吧……

2015-03-10 15:58:25 +08:00
 Loop680
The len() function is used to count how many characters a string contains.
Get the first half of the string stored in the variable 'phrase'.
Note: Remember about type conversion.

phrase = """
It is a really long string
triple-quoted strings are used
to define multi-line strings
"""
first_half = ???????
print(first_half)

就是问???那里写什么,我一直没搞懂first_half指什么。
3041 次点击
所在节点    Python
6 条回复
cloverstd
2015-03-10 16:16:24 +08:00
first_half = phrase[:len(phrase)]
我想是这样的
stupidcat
2015-03-10 16:18:06 +08:00
half嘛 就是一半 first half就是前面一半 所以len()/2 再切片就好 是不是我想得太简单了
lingxi27
2015-03-10 16:21:25 +08:00
phrase[0:len(phrase)//2]

截取前半部分,大概是这个意思吧
Loop680
2015-03-10 16:24:32 +08:00
@cloverstd
@stupidcat
@lingxi27
多谢多谢,就是这样哈。
mengjue
2015-03-10 16:25:47 +08:00
就是前半的意思,英语需要好好学习。
first_half = phrase[:len(phrase)//2]应该就编译通过了。
Loop680
2015-03-10 16:49:39 +08:00
@mengjue 我是直接用88/2写进去,太耿直了……

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/175842

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX