两个python初学者问题 [英] two python beginner questions

查看:63
本文介绍了两个python初学者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程的新手,我正在尝试自学python。我有两个问题,你如何使用for循环打印列表中的行与行号然后单词然后我也想知道标签是什么打印出三个最长,最短和中等长度的单词与他们的实际长度

解决方案


我是编程的新手,我正在尝试自学python。我有两个问题,你如何使用for循环打印列表中的行与行号然后单词然后我也想知道标签是什么打印出三个最长,最短和中等长度的单词与他们的实际长度



在我的头顶,这里是第一部分:

展开 | 选择 | Wrap | 行号

谢谢,这是有道理的我无法找到一个示例显示使用枚举来对列表中的行进行编号,这确实有帮助。行打印的确切内容"%d:%s"%(i,word)是什么意思?



谢谢,这是有道理的我找不到一个示例显示使用枚举来对列表中的行进行编号,这确实有帮助。线条打印到什么时候%d:%s%(i,word)是什么意思?



这称为字符串格式化。在引号内,%具有特殊含义。 此处是文档。

基本上,它表示打印一个(d)ecimal后跟一个'':''后跟一个(s)tring,其中十进制在i中,字符串在word中(实际上是(i,word) )元组)。


I am new to programming and am trying to teach myself python. I have two questions how do you use a for loop to print out the lines from a list with the line numbers then the word and then I also was wondering what the tag was to print out the three longest, shortest, and middle length words along with their actual lengths

解决方案

I am new to programming and am trying to teach myself python. I have two questions how do you use a for loop to print out the lines from a list with the line numbers then the word and then I also was wondering what the tag was to print out the three longest, shortest, and middle length words along with their actual lengths

Off the top of my head, here''s the first part:

Expand|Select|Wrap|Line Numbers


Thanks, that makes sense I couldn''t find an example showing to use enumerate to number the lines of the list anywhere, this really helped. What exactly does the line print "%d: %s"%(i, word) mean?


Thanks, that makes sense I couldn''t find an example showing to use enumerate to number the lines of the list anywhere, this really helped. What exactly does the line print "%d: %s"%(i, word) mean?

That''s called "string formatting". Inside quotes the % has special meaning. Here is the documentation.

Basically, it says print a (d)ecimal followed by a '': '' followed by a (s)tring, where the decimal is in i and the string is in word (actually the (i, word) tuple).


这篇关于两个python初学者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆