Python 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。
Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有比其他语言更有特色语法结构。
Python 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。
Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有比其他语言更有特色语法结构。
1.create list
eg.
>>> a=["python",25,89.9]
>>> a
["python",25,89.9]
2.list index
eg.
>>> a=["python",25,89.9]
>>> a[0]
'python'
>>> a[1]
25
>>> a[2]
89.9
>>> a[-1]
89.9
#get the index ...
1)s={1,"python"}
2)s=set("python") or s=set([1,"python"])
ps. set to list:
lst=list(s)
list to set(can remove duplicate elements from the set):
s=set([1,"python"])
Create an immutable set in "frozenset"
1)add
eg.
b ...
cases = {
case1: do_some_stuff1,
case2: do_some_stuff2,
...
caseN: do_some_stuffN,
}
cases.get(var, do_default_stuff)()
result = {
'a': lambda x: x * 5,
'b': lambda x: x + 7,
'c': lambda x: x - 2
}[value](x)
import pickle
#dumps(object) :Object serialization
lista=["john","levi","kate"]
listb=pickle.dumps(lista)
#print listb
#loads(string) :The object is restored, and the object type is restored to the original format.
listc=pickle.loads(listb)
#print listc
#dump(object,file) :To store objects in a file.
group1=("cat","is","kkkk")
f1=file ...
1)Constant
eg.
import const
const.value=5
print const.value
const.value=6
2)Variable
eg.
a=1
1)Single quotation mark
eg. a='string'
2)Double quotation marks
eg. b="string"
3)Three single quotation marks (output special characters)
eg. c='''string ...
Python read and write file
fr=open("readfile.txt","r")
fw=open("writefile.txt","w")
print fr.readline()
print fr.tell()
print fr.readlines()
fw.write("===write line===")
fw.close()
fr.seek(0,0) #The first parameter represents the number of bytes, after which a parameter represents the relative ...
# -*- coding: utf-8 -*-
import random
def generate_verification_code():
''' randomly generated a 6 bit verification code '''
code_list = []
for i in range(10): # 0-9 number
code_list.append(str(i))
for i in range(65, 91): # A-Z
code_list.append(chr(i))
for i in range(97, 123): # a-z
code_list.append(chr(i))
myslice = random.sample(code_list, 6)
verification_code ...
pip install virtualenv
virtualenv envfolder(Virtual environment name)
After you create a successful, will generate the corresponding directory files in the current directory.
cd envfolder/
Then start
source ./bin/activate
deactivate