# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# https://edube.org/quiz/pe-2/pe2-summary-test-1

# the sys.stderr stream is normally associated with:
#     the keyboard
#     the screen
#     the printer
#     a null device *

# +
# file a.py
print("a",end='')

#file b.py
import a
print("b",end='')

#file c.py
print("c",end='')
import a
import b
'''out put cab'''


# -

class A:
    def __init__(self):
        pass
a =A(1)
print(hasattr(a, 'A'))

# +
try:
    raise Exception
    
except Exception:
    print("b")
except BaseException:
    print("a")
except:
    print("c")

# +
try:
    raise Exception
    
except BaseException:
    print("a")
except Exception:
    print("b")
except:
    print("c")
# -

try:
    raise Exception
except:
    print("c")
except BaseException:
    print("a")
except Exception:
    print("b")


class A:
    A = 1
    def __init__(self):
        self.a =0
print(hasattr(A, 'a'))

# !pip3 --version

from datetime import timedelta
d = timedelta(weeks=1, days=7,hours=11)
print(d*2)


# +
#generator 

class I:
    def __init__(self):
        self.s='abcd'
        self.i=0
        
    def __iter__(self):
        return self
    
    def __next__(self):
        if self.i==len(self.s):
            raise StopIteration
        v=self.s[self.i]
        self.i+=1
        return v
    
for x in I():
    print(x, end='')
# -

import calendar
calendar.setfirstweekday(calendar.SUNDAY)
print(calendar.weekheader(3))

numbers=[0,2,7,9,10]
foo=map(lambda num: num**2, numbers)
print(foo)
print(list(foo))

numbers=[i*i for i in range(5)]
foo=(filter(lambda num: num%2, numbers))
print(foo)
print(list(foo))


# +
class A:
    def __init__(self,v=2):
        self.v =v
    def set(self, v=1):
        self.v +=v
        return self.v
    
a =A()
print(a.v)
b=a          
print(a.v)
b.set()
print(a.v)

print(id(a),id(b))
'''a, b are same obj'''


# +
class A:
    A = 1
    def __init__(self):
        self.a =0

print(hasattr(A,'a'))
print(hasattr(A,'A'))


# -

class A:
    A = 1
    def __init__(self):
        self.a =0
b=A()
print(hasattr(b,'a'))
print(hasattr(b,'A'))


class A:

    def __init__(self,v):
        self.__a =v+1
b=A(0)
print(hasattr(b,'__a'))
print((b.__a))

# if there are more that one except: branches after the try: clause, we can say that:not more than one except: block will executed
#

print(len("\\\\"))


# +

print(len("\\\"))
# -

try:
    raise Exception(1,2,3)
except Exception as e:
    print(len(e.args))

for x in open('text.txt','rt'):
    print('----------------------')
    print(x)
'''read file line by line'''





# +
class A:
    pass
class B(A):
    pass
class C(B):
    pass

print(issubclass(A,C))
print(issubclass(C,A))

# -

import random
a=random.choice((0,100,3))
b=random.randrange(10,100,3)
c=random.randint(0,100)
print(a,b,c)


# +
class A:
    def a(self):
        print('a')
        
class B:
    def a(self):
        print('b')
        
class C(B,A):
    def c(self):
        self.a()

o=C()
o.c()


# +
#closure
def o(p):
    def q():
        return '*' * p
    return q

r = o(1)
s = o(2)
print(r() + s())

# +
#what will be the output of the following code, located in the p.py file?
print(__name__)

#__main__
# -

#yiled test
def f (n):
    s = '+'
    for i in range(n):
        s += s  # double up
        yield s
for x in f(3):
    print(x, end=' ')



StarcoderdataJupyterScriptsDedupFiltered