python列表支持in运算符吗_Python列表和运算符

从学习Python艰难的方式:

Python sees you mentioned mystuff and looks up that variable. It might have to look backwards to see if you created with =, look and see if it is a function argument, or maybe it’s a global variable. Either way it has to find the mystuff first.

Once it finds mystuff it then hits the . (period) operator and starts

to look at variables that are a part of mystuff. Since mystuff is a

list, it knows that mystuff has a bunch of functions.

It then hits append and compares the name “append” to all the ones

that mystuff says it owns. If append is in there (it is) then it grabs

that to use. Next Python sees the ( (parenthesis) and realizes, “Oh

hey, this should be a function.” At this point it calls (aka runs,

executes) the function just like normally, but instead it calls the

function with an extra argument.

That extra argument is … mystuff! I know, weird right? But that’s

how Python works so it’s best to just remember it and assume that’s

alright. What happens then, at the end of all this is a function call

that looks like: append(mystuff, ‘hello’) instead of what you read

which is mystuff.append(‘hello’).

他从哪里得到“mystuff”?而且我仍然不确定那段时期的运算符是如何工作的(对不起,我是新来的,请耐心等待我),稍后我们得到这个:

ten_things = "Apples Oranges Crows Telephone Light Sugar"

print "Wait there's not 10 things in that list, let's fix that."

stuff = ten_things.split(' ')

我没有看到该字符串如何成为最后一行之后的列表,.split会自动将其转换为一个或什么?他正在做的那段“分裂”或“追加”事物的名称是什么?搞砸我编程的主要原因之一就是我不知道实际上有多少东西被称为.我知道函数,变量等,但是像.split这样的东西只会让我困惑.

救命?

解决方法:

关于“他从哪里得到”mystuff“from?”,mystuff是某种对象,对象的属性值(或其类的属性值)中有方法或函数.点(句点)是限定词运算符;例如,mystuff.append限定或标识相关的追加函数是与对象mystuff相关联的函数.对象方法通常具有隐式参数(通常称为self)作为第一个参数,并且该参数等于方法所属的对象.在这种情况下,这是mystuff.

如前一个答案中所述,split拆分字符串并返回列表.有关更多信息,请参阅有关拆分的tutorialspoint:

The method split() returns a list of all the words in the string, using str as the separator (splits on all whitespace if left unspecified), optionally limiting the number of splits to num. … Following is the syntax for split() method: str.split(str="", num=string.count(str)).

标签:python

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值