python 内置函数_Python简介,第6章–内置函数和方法

python 内置函数Magic-wielding escapees were desperately deflecting the Imperial attacks on the fortress’ supports as best they could. Ranks of longbowmen rained down arrows, but conjured gusts of wind ...
摘要由CSDN通过智能技术生成

python 内置函数



Magic-wielding escapees were desperately deflecting the Imperial attacks on the fortress’ supports as best they could. Ranks of longbowmen rained down arrows, but conjured gusts of wind sent many of them flying back the other way. The rebels were holding the Imperials off for the moment, but Baldric could see it was only a matter of time before they all took a dive, like so many employees before them, into the lake of fire.

中号 AGIC挥舞逃亡者拼命偏转,因为他们可以在最好的堡垒支持帝国的攻击。 弓箭手的队伍如雨点般落下,但是阵阵阵阵狂风使许多人以相反的方式飞回。 叛军暂时阻止了帝国军的进驻,但鲍德瑞克(Baldric)看到,像所有人一样,他们都跳入了火湖,这只是时间问题。

Of course, HR prisoners usually died by some other means first, such as repeated staff meetings. Ten a day, Baldric had heard. Then they were bundled up and stacked like firewood as he’d seen below before being tossed in the lava. Bundled up…the shrouds…

当然,人力资源囚犯通常会首先通过其他方式死亡,例如反复召开员工会议。 鲍德里克每天听到十声。 然后将它们捆起来,像柴火一样堆起来,就像他在下面看到的那样,然后扔进熔岩中。 捆绑了……裹尸布……

“Cassandra, the death shrouds HR uses. We’ve got some powerful Wind users here. What if we all grab a shroud and let the Wind guys float us out of here!?”

“卡桑德拉,死亡笼罩着人力资源部门。 我们这里有一些强大的Wind用户。 如果我们都抓起裹尸布,让风团伙把我们从这里赶出来,该怎么办!?”

One of the Wind users, a graying gnome, looked up at them. He seemed to think for a moment, then shrugged and said, “It won’t be easy, but we might be able to manage it.”

一个Wind用户,一个灰色的侏儒,抬头看着他们。 他似乎想了一会儿,然后耸了耸肩,说道:“这并不容易,但我们也许可以管理。”

After a moment of thought, Cassandra nodded. “The Great Serpent help us if that’s the best we’ve got. Sigh, get to it immediately.”

片刻之后,卡桑德拉点了点头。 “如果那是我们所能做到的最好的话,大蛇会帮助我们。 叹息,马上去。”

Baldric flew down the stairs and back to the storerooms of Block A. Weaving arms of Wind that gathered up all the shrouds into one big bundle, he carried them up to the roof, sweating with the concentration it took to maintain the flows of Wind. He emerged from the trapdoor back among the prisoners and pulled a huge bundle of shrouds up after him.

鲍德瑞克飞下楼梯,回到A块的储藏室。编织的风把所有的罩子捆成一捆,编织成一捆,然后抬起屋顶,集中精力维持风的流动。 他从囚犯的活板门中走出来,并在他身后拉出一大捆裹尸布。

Cassandra had apparently briefed everyone on the plan because on cue several individuals at a time ran over to the shrouds and quickly began unfolding and reconfiguring them and the accompanying ropes so that they became a sort of makeshift parasail wing with a rope through the middle of each of the two shorter sides that was then tied around one’s torso. But the rebel Magic users were visibly tiring from the efforts of the defense, and the additional lapse from rebels seeing to their escape shrouds gave the Imperials an opening. With a sickening crunch Baldric felt a main support give way.

卡桑德拉显然已经向所有人简要介绍了该计划,因为一次提示几个人跑到了围带上,并Swift展开并重新配置了围带和随附的绳索,以使它们成为一种临时的帆板机翼,每条绳索的中间都穿过绳索然后将两个短边中的一个绑在一个人的躯干上。 但是,叛军魔术师的用户显然在防御的努力上很累,而叛军看到逃生围裙的额外失误为帝国开辟了一块空地。 随着令人作呕的紧缩,波德里奇感到了主要的支持。

“Everyone ready?” Cassandra shouted.

“每个人都准备好了吗?” 卡桑德拉大喊。

One of the prisoners shouted back, “Wait, we’re short a shroud!” A 4-foot diameter fireball from the Imperials streaked through the air, leaving no trace of the prisoner it passed through behind.

其中一名囚犯大喊:“等等,我们简直是寿衣!” 帝国军发射的直径为4英尺的火球在空中划过,没有留下任何痕迹。

“Alright we’re good to go,” Cassandra responded. “Wind channelers, get us off this Light-forsaken thing!”

“好吧,我们很好。”卡桑德拉回答。 “风道者,让我们摆脱被光明抛弃的事情!”

Just as the fortress gave way under everyone’s feet, Baldric felt a strong updraft that instantly filled his death shroud parachute and carried him skyward. Like dandelion seeds, the ragtag rebels were blown through the air to the east towards the Teleportation Circle. The Imperials, caught by surprise, tried to pick them off with arrows and Magical projectiles, but the rebels were soon outside their range and on their way back to the city proper.

就像要塞在所有人的脚下屈服一样,鲍德瑞克感到强烈的上升气流,立即将他的死亡裹尸布降落伞降落,并抬高了他。 就像蒲公英的种子一样,破布的叛乱分子从空中被吹向东方,朝着隐形传送带。 帝国军措手不及,试图用箭和魔法弹头将他们赶下,但叛军很快就超出了他们的射程,并返回城市。

Cassandra floated over to Baldric. “We’ll be at the Teleportation Circle in several minutes, and you’ll need to unlock it ASAP. You’ll find three stone sphinxes, and each will have a puzzle to solve. Once those are are taken care of, that key I gave you will activate the Circle. I must warn you though, the puzzles involve heavy use of built-in functions, string methods, and list methods. But I have no doubt you can do it.”

卡桑德拉漂流到博尔德里克。 “我们将在几分钟之内到达Teleportation Circle,您需要尽快将其解锁。 您会发现三个石狮身人面像,每个都需要解决一个难题。 一旦解决了这些问题,我给您的那把钥匙就会激活圈子。 不过,我必须警告您,这些难题涉及大量使用内置函数,字符串方法和列表方法。 但我毫不怀疑您可以做到。”

“Well, that makes one of us,” Baldric muttered to himself. He began to ponder his chances of unlocking the Circle. Was he at that level yet? He knew at the very least he had a whole lot more to learn about built-in functions and methods, and he decided to see what he could figure out on his own.

“好吧,这使我们成为其中之一。”鲍德里克自言自语。 他开始考虑解锁圈子的机会。 他在那个水平了吗? 他至少知道,他还有很多要学习的有关内置函数和方法的知识,因此他决定看看自己能解决什么。

狮身人面像1 (Sphinx 1)

“I know that a built-in function is a function just like all the ones I’ve written, except I don’t actually have to write it. It’s just always there in the background, waiting for me to use it. And actually, now that I think about it, I’ve already used a lot of built-in functions without even realizing it.”

“我知道内置函数就像我编写的所有函数一样,只是我实际上不必编写它。 它一直都在后台,等着我使用它。 实际上,考虑到这一点,我已经使用了很多内置函数,甚至没有意识到它。”



print() Displays, or “prints out”, what’s passed into it. Useful in script mode where values aren’t printed to the console unless this function is called.

print ()显示或“打印出”传入的内容。 在脚本模式下很有用,在该模式下,除非调用此函数,否则不会将值打印到控制台。

# in interactive mode, print() often acts the same as just entering an expression without print()
>>> 2 + 2
4

>>> print(2 + 2)
4
# in script mode, the result of 2+2 is not displayed
2 + 2


# but with print(), now the script does print out the resulting value
print(2 + 2)
4



type() Identifies the type of a given object.

type ()标识给定对象的类型。

>>> type(4)
<class 'int'>

>>> type("aren't there ever any bathroom breaks in adventures?")
<class 'str'>


int() Converts the passed object to an integer.

int ()将传递的对象转换为整数。

>>> int(4.2)
4

>>> int(4.9)
4

>>> int("4")
4


float() Converts the passed object to a float.

float ()将传递的对象转换为float。

>>> float(4)
4.0

>>> float("4")
4.0


str() Converts the passed object to a string.

str ()将传递的对象转换为字符串。

>>> str(4)
'4'


list() Converts the passed object to a list.

list ()将传递的对象转换为列表。

>>> list('rebellion')
['r', 'e', 'b', 'e', 'l', 'l', 'i', 'o', 'n']


range() Returns an iterable sequence of integers. Often used with for loops.

range ()返回整数的可迭代序列。 常与for循环一起使用。

>>> for i in range(1,5):
        print(i)
1
2
3
4

>>> for i in range(3):
        print(i)
0
1
2


len() Returns the length of a given object.

len ()返回给定对象的长度。

>>> len("sphinx")
6

>>> len(["sphinx 1", "sphinx 2", "sphinx 3"])
3


“That’s quite a lot right there. But I wonder if there are other, perhaps even more powerful, built-in functions,” Baldric thought to himself.

“那有很多。 但我想知道是否还有其他甚至可能更强大的内置功能,” Baldric自言自语。

“Ah, excuse me Cassandra, I’ve got to go ask Boomdoom about something.” Baldric spotted the massive half-orc and floated over to him.

“啊,对不起,卡桑德拉,我得去问Boomdoom些事。” 鲍德里克发现了庞大的半兽人,然后向他漂浮。

“Uhh, hey Boomdoom.”

“呃,嘿&

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值