Instantly share code, notes, and snippets.

# yhilpisch/00_bc_day_1_section_02 Last active Oct 3, 2017

Gist with additional files from For Python Quants Bootcamp, May 2017, New York City
 3 + 4 3 * 4 3 / 4 type(3) type(4) 3 ** 4 sqrt(3) 3 ** 0.5 import math math.sqrt(3) print("Python.") a = 3 b = 0.75 c = 'Python.' d = "He said:'I am late.'" d d = "He said:"I am late."" d = 'He said:"I am late."' d a print(a) a b a * b a ** b d 2 * d d + d d + d * 2 d / d d / 2 d d[0] d[1] len(d) d[20] d[19] d[-1] d[-2] d[-20] d[-21] d[2] d[:2] d[:2] + d[2:] d[2:] d[2:7] d[2:7:2] d[::2] d[::-1] range(10) type(range(10)) for i in range(10): print('For Python Quants') for i in range(10): print(i) for i in range(10): print(i ** 2) %magic %lsmagic %hist %hist? %history? len? for i in range(10): print(d[i]) for c in d: print(c) for _ in d: print(_) c for _ in d: print(_, end='') for _ in d: print(_, end='|') for x in range(10): print(x) for x in range(10): print(x ** 2) l = [x for x in range(10)] l l = [x ** 2 for x in range(10)] l type(l) l2 = [x ** 2 for x in range(10) if x > 2] l2 l2 = [x ** 2 for x in range(10) if (x > 2) and (x < 8)] l2 l[0] l[:5] l[5:] l[::-1] l = [x ** 2 for x in range(10)] 10 % 2 11 % 2 l = [x ** 2 for x in range(10) if x % 2 == 0] l l = [x for x in range(20) if x % 2 == 0] l for x in range(20): for y in range(10, 50): if x % 2 == 0: # then do something pass def f(x): return x ** 2 f f(10) f(10.5) l = [f(x) for x in range(20) if x % 2 == 0] l l3 = [5, 'fpq', a, l] l3 l3.append('this is new') l3 l3.append(f) l3 l3[-1](5) l.append('new') l l3 l l3 def is_prime(I): for i in range(2, I): if I % i == 0: return False return True is_prime(8) is_prime(10) is_prime(11) is_prime(13) l = [is_prime(x) for x in range(2, 101)] l l = [is_prime(x) for x in range(2, 20)] l class MyClass(object): pass class my_class(object): pass int(Ture) int(True) int(False) while True: print('hi') while 2: print('hi') 2 == 2 True == 2 True == 1 def is_prime_2(I): for i in range(2, I ** 0.5): if I % i == 0: return False return True is_prime_2(10) def is_prime_2(I): for i in range(2, int(I ** 0.5)): if I % i == 0: return False return True int(2.3) int(2.7) def is_prime_2(I): for i in range(2, int(I ** 0.5) + 1): if I % i == 0: return False return True is_prime_2(10) is_prime_2(11) %ed p1 = int(1e8 + 1) p2 = int(1e8 + 3) p1 p2 is_prime(p1) is_prime(p2) p2 = 2** 17 − 1 p2 = 2 ** 17 - 1 p2 p2 = 2 ** 31 - 1 p2 %time is_prime(p1) %time is_prime(p2) p2 = 2 ** 17 - 1 %time is_prime(p2) %time is_prime_2(p2) %time is_prime_2(int(2**31 - 1)) def is_prime_3(I): if I % 2 == 0: return False for i in range(3, int(I ** 0.5) + 1, 2): if I % i == 0: return False return True %time is_prime_3(int(2**31 - 1)) %ed is_prime_3 %ed -p from math import sqrt sqrt(4) ls cd .. ls cd bc !mkdir bc cd bc/ %hist -f bc_day_1_section_02
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.