我是靠谱客的博主 丰富大树,最近开发中收集的这篇文章主要介绍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

最后

以上就是丰富大树为你收集整理的python列表支持in运算符吗_Python列表和运算符的全部内容,希望文章能够帮你解决python列表支持in运算符吗_Python列表和运算符所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(33)

评论列表共有 0 条评论

立即
投稿
返回
顶部