1. Set Set
Set set is an unordered and non-repeating collection
Add Features:
S1 = set ()
S1.add ("Wang")
Print (S1)
Difference function (find different elements from the current collection and generate a new collection):
S1 = set (["Wang", "Pan", "Lai"])
S2 = s1.difference (["Wang", "Pan"])
Print (s2)
Result: {' Lai '}
Difference_update (removes duplicate elements from the current collection, does not generate a new collection):
S1 = set (["Wang", "Pan", "Lai"])
S1.difference_update (["Pan", "Lai"])
Print (S1)
Result: {' Wang '}
1. Queue
Single queue: FIFO
Bidirectional queue (Collections): Both sides can be entered and taken
2. Dictionary {}, tuple (), list []
3. Deep Copy (Copy.deepcopy ()) and shallow copy (Copy.copy ())
For both numbers and strings, the result memory address is the same
4. Functions
The try statement in the function:
#-*-Coding:utf-8-*-
# Author:cslzy
# email: [Email protected]
# description:send something to someone.
# date:20151104 18:33:08
Import Smtplib
From Email.mime.text import Mimetext as MT
def Mail (user):
ret = ' ture '
Try
msg = Mimetext (' Hello! ', ' Plaon ', ' utf-8 ')
msg[' from ' = formataddr ([' Wang Hope ', ' [email protected] ')
msg[' to ' = formataddr ([' Wang Hope ', ' [email protected] ')
msg[' Subject ' = ' theme '
Server = Smtplib. SMTP (' smtp.126.com ', 25)
Server.login (' [email protected] ', ' password ')
Server.sendmail (' [email protected] ', [User,],msg.as_string ())
Server.quit ()
Except Exception:
ret = ' false '
return ret
ret = mail (' [email protected] ')
Print (ret)
The default parameter must be written back.
Dynamic Parameters (*: tuple, * * dictionary):
Def han (*arg,**karg):
Print (Arg,type (ARG))
Print (Karg,type (Karg))
Han (7,89,3,62,n1=78,n2=88)
Def han (*arg,**karg):
Print (Arg,type (ARG))
Print (Karg,type (Karg))
L1 = [7,89,3,62]
L2 = {' N1 ': +, ' N2 ': 88}
Han (*l1,**l2)
#l1 = ' {0} is {1} '
L1 = ' {name} ' is {role} '
N1 = {' name ': ' Ren ', ' role ': ' Dashen '}
#l2 = L1.format (' ren ', ' dashen ')
#l2 = L1.format (name= ' ren ', role= ' Dashen ')
L2 = L1.format (**n1)
Print (L2)
Simple function lambda expression:
code comment for python #-*-Coding:utf-8-*-
If you want to write Chinese in the Python2 py file, you must add a line to declare the file encoded comments, otherwise python2 will use ASCII encoding by default.
Reference: http://blog.csdn.net/arbel/article/details/7957782
Python built-in functions:
Http://www.runoob.com/python/python-built-in-functions.html
Python Learning Note Day4