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 # ========================================== # add zeros at the start of string '22'.zfill(10) # out: '0000000022' # ========================================== # make iterable slice from itertools import islice islice(iterable, stop) islice(iterable, start, stop) islice(iterable, start, stop, step) # ========================================== # write directly to the file with open('/tmp/filename', 'w') as f: # python2 print >> f, 'some_text' # python3 print("some_text", file=f) # ========================================== # try statement try: # something except: # if exception was raised else: # if try was successfully finally: # do this stuff in any case # ========================================== # lambda function f = lambda x: x**2 lambda x: x if (x < 3) else None # ========================================== # get input from shell for line in sys.stdin: print("You entered: ", line) # and after entering required data to the shell press ctrl+D # ========================================== # get first and last line of the file with open("using_python_to_profit") as f: first, *_, last = f.readlines()