Professional Documents
Culture Documents
This
is mostly used in unix based environment. Mac also need this.
To print : print(“Hello”)
Conditional
if a < b: see if else structure, all code indented becomes part of the if or else
print('a ({}) is less than b ({})'.format(a, b)) see here {} will be replaced by a and b
else:
Ternary operator
While loop
a, b = 0, 1
print(b)
b=b+1
For loop
fh = open('lines.txt')
print(line)
Define function
def isprime(n):
if n == 1:
print("1 is special")
return False
if n % x == 0:
return False
else:
return True
isprime(n)
Generator function
def isprime(n):
if n == 1:
return False
if n % x == 0:
return False
else:
return True
while(True):
for n in primes():
print(n)
class Fibonacci():
self.a = a
self.b = b
def series(self):
while(True):
yield(self.b)
f = Fibonacci(0, 1)
for r in f.series():