首页 / PYTHON / Python列表和运算符
Python列表和运算符
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python列表和运算符,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2338字,纯文字阅读大概需要4分钟。
内容图文
![Python列表和运算符](/upload/InfoBanner/zyjiaocheng/816/2463391496d14e3ea4f1631348acca1c.jpg)
从学习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列表和运算符所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。