Format Python

From ElectroDragon Wiki
Revision as of 00:06, 29 April 2021 by Chao (talk | contribs) (Created page with "== Format == === String Format === <syntaxhighlight lang="python"> print("I'm %s. I'm %d year old" % ('Vamei', 99)) print ('this is %s %%') (% date) # %% to print % </syntaxhi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Format

String Format

print("I'm %s. I'm %d year old" % ('Vamei', 99))
print ('this is %s %%') (% date) # %% to print %
  • s.strip() .lstrip() .rstrip(',') remove empty space, and special words

Format type

  • print type(aaa) # print type of aaa variable
  • print len(aaa) # print length

Change format

a = float(b) change to type float

Module String

Replace

import string
a = 'abcde'
b = string.replace(a, 'ab', '', 1)
print b