file = open('FILENAME', mode)
mode --r,w,x,a,b,+
f = open("test.txt", "w")
f.readline() --type str
f.readlines() -- type list
file = open('FILENAME', mode)
mode --r,w,x,a,b,+
f = open("test.txt", "w")
f.readline() --type str
f.readlines() -- type list
video = {'betaVideo':'beta.avi', 'motionVideo':'motion.mp4', 'videoLength':12}
video['betaVideo'] --> 'beta.avi'
video.get('betaVideo') --> 'beta.avi'
video['check'] --> 'KeyError: 'check''
video.get('check') --> None
video.get('check', 'nothing') --> 'nothing'
video['betaVideo']='test.avi'
--> {'videoLength': 12, 'motionVideo': 'motion.mp4', 'betaVideo': 'test.avi'}
videoFile['director']='sboku'
-->{'director': 'sboku', 'videoLength': 12, 'motionVideo': 'motion.mp4', 'betaVideo': 'test.avi'}
video = dict(betaVideo='betaVideo.avi', motionVideo='motionVideo.mp4', videoLength=100)
-->
{'betaVideo': 'betaVideo.avi', 'motionVideo': 'motionVideo.mp4', 'videoLength': 100}
author = {'Author':'sboku'}
video.update(author)
-->
{'betaVideo': 'betaVideo.avi', 'motionVideo': 'motionVideo.mp4', 'videoLength': 100, 'Author': 'sboku'}
video.keys()
--> dict_keys(['betaVideo', 'motionVideo', 'videoLength', 'Author'])
video.values()
--> dict_values(['betaVideo.avi', 'motionVideo.mp4', 100, 'sboku'])
video.items()
--> dict_items([('betaVideo', 'betaVideo.avi'), ('motionVideo', 'motionVideo.mp4'), ('videoLength', 100), ('Author', 'sboku')])
s ='test.com'
l = list(s) --> ['t', 'e', 's', 't', '.', 'c', 'o', 'm']
l[-1] = 'n' --> ['t', 'e', 's', 't', '.', 'c', 'o', 'n']
s = ''.join(l) --> 'test.con'
s = '3'.join(l) --> 't3e3s3t3.3c3o3n'
url = 'getronics.com,yahoo.co.jp,nikkei.com'
type(url) --> <class 'str'>
url = url.split(',') --> ['getronics.com', 'yahoo.co.jp', 'nikkei.com']
type(url) --> <class 'list'>
url = 'getronics.com'
url.startswith('g') --> True
url.endswith('com') --> True
url.find('getronics') --> 0
url.find('com') --> 10
a,b = 1,2 a -->1, b--> 2
'{0} --> {1}'.format(a,b) --> '1 --> 2'
'{name} --> {age}'.format(name = 'jerry', age = '100') --> 'jerry --> 100'
('{name} --> {age}'.format(name = 'jerry', age = '100')).upper() --> 'JERRY --> 100'
[c*3 for c in 'CODE'] --> ['CCC', 'OOO', 'DDD', 'EEE']
['nikkei.com'] * 3 --> ['nikkei.com', 'nikkei.com', 'nikkei.com']
l = ['nikkei.com']
l.extend(['test.com', 'getronics.com']) --> ['nikkei.com', 'test.com', 'getronics.com']
l[0] --> 'nikkei.com'
l[1] --> 'test.com'
l = ['nikkei.com']
l.append(['test.com', 'getronics.com']) --> ['nikkei.com', ['test.com', 'getronics.com']]
l[0] --> 'nikkei.com'
l[1] --> ['test.com', 'getronics.com']
l.sort(), l.reverse(),
l.index('nikkei.com') --> 0
l.count('nikkei.com') --> 1
l1 = [1, 2, 3, 4, 5]
l2 = l1
l2 --> [1, 2, 3, 4, 5]
l1[0] = 10
l2 --> [10, 2, 3, 4, 5]
l2 = l1[:] or l2 = l1.copy()
l1[0] = 11 --> [11, 2, 3, 4, 5]
l2 --> [10, 2, 3, 4, 5]
'f={0}'.format(x)
'f=x'
'f={0:.3f}'.format(3.333333)
'f=3.333'
d = {'name':'sboku', 'age':'30', 'job':'engineer'}
'name:{0}, age:{1}'.format(d.get('name'), d.get('age'))
10//4 --> 2
10//4.0 -->2.0
import math
math.floor(3.4) -->3 math.floor(3.9) --> 3
math.floor(-3.4) -->-4 math.floor(-3.9) --> -4
math.trunc(3.9) -->3 math.trunc(-3.9) --> -3
0o 8进制, 0x 16进制, 0b 2进制
转换 oct(), hex(), bin()
"what's your name" == 'what\'s your name'
s = "asdfasdfagaf"
s[:] --> 'asdfasdfagaf'
s[-1] --> 'f', s[:-1] --> 'f'
s[::2] --> 'adadaa'
s[::3] --> 'afdg'
解释器,PVM
解释器-- 字节码
PVM执行字节码