My Python Cheatsheet

06 Dec 2021

Tested On

Python: python3.8

Procedure

with open("test.txt", mode='w') as f:
    f.write("my first file\n")
    f.write("Hello World!")
with open("test.txt", mode='o') as f:
    list = f.readlines()
    for line in list:
        print line
squares = [x**2 for x in range(10)]
words = ["I", "love", "hummus", "a", "lot"]
short_words = [word for word in words if len(word) <= 3 ] # short_words = ["I", "a", "lot"]