mtwm.net
当前位置:首页 >> Python题,求大神解答 >>

Python题,求大神解答

s[i:].find(t)+ifind(t,i),t是搜索的关键字,i是搜索开始的位置,返回的是找到的关键字在字符串s中的位置所以,第二个选项明显错误,find返回是一个数字,不能再截取字符串第四个选项t[i:]明显错误,连搜索的关键字都变短了第一个第三个都是先把字符串缩短i位再从缩短的字符串开头查找,和直接从字符串i位开始查找是一样的,但结果需要加上i,所以选第三项我错了当找不到的时候返回-1,所以单纯的+1是不行的,选最后一项,都不对

#!/usr/bin/env python# coding = utf-8KNOWTREE = dict( # does it have a backhone? True = dict( # does it give birth to live babies True = "Mammal", False = dict( # does it have feathers True = "Bird", False = dict( # does it have gills True = "

ab=list(zip(a,b))

# -*- coding:utf-8 -*-def encrypt(orgs): try: news=[str((int(i)+9)%10) for i in orgs] res=news[2]+news[3]+news[0]+news[1] return res except Exception,e: print orgs,eprint encrypt('1234')>>>2301

如果列表包含偶数个元素,则填充空格以打印列表的第一个元素list = [1,2,3,4]if len(list) % 2 == 0:XXXXprint list[0] #4个X代表空格

>>> def number(): n = raw_input('Enter your phone number:') list = [] if len(n) == 8 and n.find('0') == -1: list.append(n) else: print 'ERROR: Invalid input'>>> number()Enter your phone number:91355511>>> number()Enter your phone number:

# python3.6import mathdef sub_function(n, x, y): if n == 1: print("1:f(x,y)=(x+y)^2=%d" % math.pow(x+y, 2)) elif n == 2: print("2:f(x,y)=max(x+y)=%d" % max(x, y)) elif n == 3: exit() else: print("输入的选项有误,请重新输入.")def main(): print

代码难度不大 可以试着这么写 listA=['name','age','sex']; listB=['zhangSan',38,'Male']; listC=[(listA[i],listB[i]) for i in range(len(listA))]; myDict=dict(listC); #myDict就是你想要的输出

#python 2.7# -*- coding: utf-8 -*-ipt_info = raw_input(u'enter full name (enter q for exit):')while(ipt_info != 'q'): if ipt_info: first = ipt_info.split()[0] print [['Good day!',"Good day Ma'am!"][first=='Ms' or first=='Miss'],'Good day Sir!'][first=='Mr'] ipt_info =

网站首页 | 网站地图
All rights reserved Powered by www.mtwm.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com