-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasetype.py
More file actions
72 lines (53 loc) · 1.37 KB
/
Copy pathbasetype.py
File metadata and controls
72 lines (53 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
#coding=utf-8
#-*- coding:utf-8 -*-
# https://zhuanlan.zhihu.com/p/20878530?refer=intelligentunit
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) / 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)
print(quicksort([3, 6, 9, 10, 11, 8, 0]))
'''
Python中没有 x++ 和 x-- 的操作符。
'''
hello = 'hello' # String literals can use single quotes
world = "world"
hw12 = '%s %s %d' % (hello, world, 12) # sprintf style string formatting
print hw12
xs = [3, 1, 2]
print xs, xs[2]
print xs[-1]
# 和列表最重要的不同在于,元组可以在字典中用作键,还可以作为集合的元素,而列表不行。
def sign(x):
if x > 0:
return 'positive'
elif x < 0:
return 'negative'
else:
return 'zero'
for x in [-1, 0, 1]:
print sign(x):
def hello(name, loud = False):
if loud:
print 'HELLO, %s' % name.upper()
else:
print 'HELLO, %s' % name
hello('Bob')
hello('Fred', loud = True)
class Creeter(object):
"""docstring for ClassName"""
def __init__(self, arg):
super(ClassName, self).__init__()
self.arg = arg
def greet(self, loud = False):
if loud:
print 'HELLO, %s!' % self.name.upper()
else:
print 'hello, %s' % self.name
g = Greet('Fred')
g.greet()
import numpy as np