小白请教python 单引号 双引号引号问题

字符串的表示:&repr函数:功能是创建一个字符串,以合法的Python&表达式的形式来表示值如下&&& print repr(&Hello Python!&)'Hello Python!'&&& print repr(1Lrepr(XXX)的功能可以用& ` XXX`&实现反引号的好处还在&&当你想打印一个包含数字的句子时,派上用场了如下&&& temp = 42&&& print &The temperature is & + tempTraceback (most recent call last):
File &&pyshell#7&&, line 1, in &module&
print &The temperature is & + tempTypeError: cannot concatenate 'str' and 'int' objects&&& print &The temperature is & + `temp`The temperature is 42注意:在Python 3.0中已经不支持反引号了,所以还是坚持用repr()函数吧&&& print &The temperature is & + repr(temp)The temperature is 42温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(2166)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'python中的引号',
blogAbstract:'        学过python的朋友应该都知道,python中包含单引号,双引号和三引号。但是他们有什么区别呢?
        其实,我个人感觉,python不同于php,其中的单引号和双引号没有区别。他们的主要作用就是尽量避免使用转义字符。例如:
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:1,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}Python(16)
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:118216次
积分:3341
积分:3341
排名:第7364名
原创:225篇
(1)(1)(1)(2)(220)查看:1151|回复:5
lb=[0,0,0,0,0,0,0,0,0,0,1,0,2,0,0,0]
qs=list(filter(lambda x:x%2,lb))
os=list(filter(lambda x:x%2==0,lb))
print (qs)
怎么出来的是
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0]
请教一下是什么问题呢
正确的该如何弄呢
引用:原帖由 米发糕 于
21:01 发表
lb=[0,0,0,0,0,0,0,0,0,0,1,0,2,0,0,0]
qs=list(filter(lambda x:x%2,lb))
os=list(filter(lambda x:x%2==0,lb))
print (qs)
怎么出来的是
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0]
请教 ... 有什么问题呢? 这个不是正常吗?
lambda x:x%2&&得到的就是 非 x%2 != 0&&的值啊
另外就相关的,
你要折腾什么?
我是想实现,取奇数项形成一个列表,偶数项形成一个列表。在[1,2,3,4,5,6,7,8,9]这个列表可以,在上面那个列表就不行呢
我似乎明白了,他是和列表中的元素的数值有关,和列表的元素下标无关。对吗
本帖最后由 米发糕 于
12:21 编辑
复制内容到剪贴板代码:&&& lb
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0]
&&& [ j for i,j in enumerate(lb) if i%2 ]& &
[0, 0, 0, 0, 0, 0, 0, 0]
&&& [ j for i,j in enumerate(lb) if i%2==0 ]
[0, 0, 0, 0, 0, 1, 2, 0]
哦这样,谢谢温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(3934)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'python中的三引号',
blogAbstract:'
Python中单引号、双引号和三引号的区别:
双引号所表示的字符串通常要写成一行如:s1 = \"hello,world\"如果要写成多行,那么就要使用\\ (“连行符”)吧,
如 s2 = \"hello,\\&&&& world\"s2与s1是一样的。
如果你用3个双引号的话,就可以直接写了,如下:s3 = \"\"\"hello,world,hahaha.\"\"\",
那么s3实际上就是\"hello,\\nworld,\\nhahaha.\", 注意“\\n”,所以,如果你的字符串里\\n很多,你又不想在字符串中用\\n的话,那么就可以使用3个双引号。
而且使用3个双引号还可以在字符串中增加注释,如下:s3 = \"\"\"hello,&&#hoho, this is hello',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:3,
publishTime:3,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}}

我要回帖

更多关于 python双引号和单引号 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信