Python - Python Misc, os, shutil

Print

Posted by Rico's Nerd Cluster on January 3, 2019

Numbers

  • Not a number float('nan'). This is often seen in 0/0
    • In numpy, this is np.nan. To check, it’s numpy.isnan()
  • Multiline Printing
1
2
3
4
print(f'''
line 1
line2
''')
  • Print float with 2 decimal digits
1
print(f"{test_acc:.2f}%")

shutil

  • remove non-empty directory:
1
shutil.rmtree(DIR)

For-Else Loop

1
2
3
4
5
6
k = 10
for i in range(k):
    print(k)
    break
else:
    print("hello")