学习Python第九天

#!/usr/bin/env python
#-*- coding:utf-8 -*-



# import copy
# n1=123
# n2=copy.copy(n1)
# from builtins import print


# def email():
# print("aaa")
# return [11,22,33]
# ret = email()
# print(ret)

# def kuaidi(p):
# print(p)
# if p==123:
# return True
# else:
# return False
#
# ret = kuaidi(1234)
# print(ret)
# def email(p,text):
# import smtplib
# from email.mime.text import MIMEText
# from email.utils import formataddr
# ret = True
# try:
# msg = MIMEText(text,'plain','utf-8')
# msg['From'] = formataddr(['aa','547879336@qq.com'])
# msg['To'] = formataddr(['陈忠贤','972732867@qq.com'])
# msg['Subject'] = '主题'
#
# server = smtplib.SMTP('smtp.163.com',25)
# server.login('547879336@qq.com','hfcyveiumwpibbhc')
# server.sendmail('547879336@qq.com',[p, ], msg.as_string())
# server.quit()
#
# except:
# #r如果上述try中的代码出现错误,自动执行except中的代码
# ret = False
# return ret
# aa = email('972732867@qq.com','aaaaaq')
# print(aa)

# def drive(name='aaa'):
# temp = name +'gogogo'
# return temp
#
# ret = drive('bb')
# print(type(ret))
# ret1 = drive()
# print(ret1)
#动态参数1
# def f1(*a):
# print(a,type(a),a[1])
#
# f1(123,45,1,2,2)

#动态参数2
# def f1(**a):
# print(a,type(a))
#
# f1(k1=123,k2=444)

# def f1(*a,**aa):
# print(a)
# print(aa)
# f1(11,22,33,k1=123,k2=321)

# def f1(*args):
# print(args,type(args))
# li = [11,22,33,44]
# f1(li)
# f1(*li)

# def f1(**kwargs):
# print(kwargs,type(kwargs));
# dic = {'k1':123,
# 'k2':321}
# f1(**dic)
# p = 'aa'
# def fun1():
# a=123
# global p
# p=3333
# print(a)
#
# def fun2():
# print(p)
#
# fun1()
# fun2()





# 写函数,检查获取传入列表或元祖对象的所有奇数位索引对应的元素,并将其座位新列表返回给调用者
# 写函数,检查传入字典的每一个value的长度,如果大于2,那么保留前两个长度的内容,并将新内容返回给调用者
# dic = {'k1':'v1v1','k2':[11,22,33,44]}ps:字典中的value只能是字符串或列表
# 写函数,利用递归获取 斐波那契数列中的第10个数,并将该值返回给调用者

# 写函数,计算传入字符串中【数字】,【字母】,【空格】以及【其他】的个数
# def fun(p):
# return p
# changdu = fun('aaa ').__len__()
# print(changdu)

# 些函数,判断用户传入的对象(字符串,列表,元祖)长度是否大于5
# def fun(*args):
# if args.__len__()<5:
# return True
# else:
# return False
# return args
# ret = fun([11,22,3,4])
# print(ret)

# 些函数,判断用户传入的对象(字符串,列表,元祖)的每一个元素是否含有空内容
# def fun(*args):
# for i in args:
# if ' ' in i:
# print('zai')
# else:
# print('buzai')
# li = ('fds',' fds','123','333')
# fun(*li)


# 写函数检查传入的列表的长度,如果大于2,那么仅保留前两个长度的内容,并将新内容返回给调用者
# def fun(*args):
# for i in args:
# chang = len(i)
# if chang>2:
# return args[2:]
# print(args)
# else:
# return args
#
# li = ['fds',' fds','123','333',321]
# aa=fun(*li)
# print(aa)
# return list[0:2] if list.count > 2 else list

posted @ 2017-11-27 10:08  枫絮  阅读(119)  评论(0编辑  收藏  举报