编程札记

P

Python3 函数调用

Python3 函数调用 #!/usr/bin/python3 # Function definition is here def changeme( mylist ): "This changes a passed list into this function" mylist = [1,2,3,4] # This would assi new reference in mylist print ("Values inside the function: ", mylist) return # Now you can call changeme function mylist = [10,20,30] changeme( mylist ) print ("Values outside the function: ", mylist)

阅读全文 ↗
P

Python3 引用传递

Python3 引用传递 #!/usr/bin/python3 # Function definition is here def changeme( mylist ): "This changes a passed list into this function" print ("Values inside the function before change: ", mylist) mylist[2]=50 print ("Values inside the function after change: ", mylist) return # Now you can call changeme function mylist = [10,20,30] changeme( mylist ) print ("Values outside the function: ", mylist)

阅读全文 ↗
P

Python3 函数调用

Python3 函数调用 #!/usr/bin/python3 # Function definition is here def printme( str ): "This prints a passed string into this function" print (str) return # Now you can call printme function printme("This is first call to the user defined function!") printme("Again second call to the same function")

阅读全文 ↗
P

Python3 时间time模块 Tzset 方法

Python3 时间time模块 Tzset 方法 #!/usr/bin/python3 import time import os os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0' time.tzset() print (time.strftime('%X %x %Z')) os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0' time.tzset() print (time.strftime('%X %x %Z'))

阅读全文 ↗
P

Python3 时间time模块 方法

Python3 时间time模块 方法 #!/usr/bin/python3 import time print ("time.time(): %f " % time.time()) print (time.localtime( time.time() )) print (time.asctime( time.localtime(time.time()) ))

阅读全文 ↗
P

Python3 id运算符

Python3 id运算符 #!/usr/bin/python3 a = 20 b = 20 print ('Line 1','a=',a,':',id(a), 'b=',b,':',id(b)) if ( a is b ): print ("Line 2 - a and b have same identity") else: print ("Line 2 - a and b do not have same identity") if ( id(a) == id(b) ): print ("Line 3 - a and b have same identity") else: print ("Line 3 - a and b do not have same identity") b = 30 print ('Line 4','a=',a,':',id(a), 'b=',b,':',id(b)) if ( a is not b ): print ("Line 5 - a and b do not have same identity") else: print ("Line 5 - a and b have same identity")

阅读全文 ↗
P

Python3 Mktime 方法

Python3 Mktime 方法 #!/usr/bin/python3 import time t = (2016, 2, 15, 10, 13, 38, 1, 48, 0) d = time.mktime(t) print ("time.mktime(t) : %f" % d) print ("asctime(localtime(secs)): %s" % time.asctime(time.localtime(d)))

阅读全文 ↗