-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdraft_string.py
More file actions
51 lines (36 loc) · 1.08 KB
/
Copy pathdraft_string.py
File metadata and controls
51 lines (36 loc) · 1.08 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
import datetime
# link: https://docs.python.org/3.7/library/string.html#format-string-syntax
'233'.format()
'{{}}/{}'.format(233) #escape
'{a}/{b}'.format(b=233, a=322) #keyword parameter
'{1}/{0}'.format(233, 322) #position parameter
'{1}/{0}/{1}'.format(233, 322)
'{0.real}/{0.imag}'.format(3+4j) #call parameter
'{0[0]}/{0[1]}'.format([23,233])
ascii('锟斤拷')
'{!a}'.format('锟斤拷')
'{:<30}'.format(233)
'{:>30}'.format(233)
'{:^30}'.format(233)
'{:*^30}'.format(233)
'{0:+f} /{0:-f} /{0: f} /{0:f}'.format(2.33)
'int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}'.format(42)
'{:,}'.format(1234567890)
'{:.2%}'.format(0.234567)
x1 = datetime.datetime(2010,7,3,14,15,58)
'{:%Y-%m-%d %H:%M:%S}'.format(x1)
class MyClass1(object):
def __init__(self, num1):
self.num1 = num1
def __str__(self):
return str(self.num1) + '233__str__()'
def __repr__(self):
return str(self.num1) + '锟斤拷__repr__()'
x1 = MyClass1(233)
'{0.num1}'.format(x1)
'{!s}'.format(x1)
'{!r}'.format(x1)
'{!a}'.format(x1)
z0 = "z0-abb"
f'z0 is {z0}'
f'z0.upper() is {z0.upper()}'