Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # exec_built-in_func_demo.py -- most likely will be updated
- # All listed in py2x probably still works in Python 3.x
- py2x = '''
- # abs(var)
- print(abs(-23))
- print(abs(3 + 5j))
- # all(var)
- print(all([]))
- print(all([1, 2, 3, 4, 5]))
- print(all("string"))
- print(all([0, 0, 1]))
- print(all([0, 0, 0]))
- print(all([1, 1, 1]))
- # any(var)
- print(any([]))
- print(any([1, 2, 3, 4, 5]))
- print(any("string"))
- print(any([0, 0, 1]))
- print(any([0, 0, 0]))
- print(any([1, 1, 1]))
- # bin(int)
- print(bin(8))
- print(bin(256))
- # bool([x])
- print(bool())
- print(bool(0))
- print(bool(1))
- print(bool("True"))
- # bytearray([source, [encoding, [errors]]])
- print(bytearray())
- print(bytearray("string"))
- print(bytearray(3))
- # bytes([source, [encoding, [errors]]])
- print(bytes())
- print(bytes(3))
- # callable(obj)
- print(callable(1))
- print(callable("string"))
- # chr(i)
- print(chr(34))
- # complex([real, [imagine]])
- print(complex())
- print(complex(1))
- print(complex(2, 3))
- print(complex('1+4j'))
- print(complex('5j'))
- # dir([obj])
- print(dir())
- print(dir(complex))
- # divmod(a, b)
- print(divmod(4, 2))
- print(divmod(7, 3))
- # enumerate(iterable, start = 0)
- print(enumerate([1, 2, 3, 4, 5, 6]))
- print(enumerate(["one", "two", "three"], 1))
- # eval(expr)
- print(eval("1+6/3"))
- print(eval("1 & 2 ^ 3 - 4"))
- # filter(function, iterable)
- filtered = filter(lambda x: x % 2 == 0, [1, 2, 3, 4, 5])
- for item in filtered:
- print("[", item, "]")
- # float([x])
- print(float())
- print(float('inf'))
- print(float("-inf"))
- print(float(" nan"))
- print(float(" 213.434235235235235 "))
- # format(obj, [spec])
- print(format(1 + 2j))
- print("{0} + {1} != {2} + {3}".format(1, 2, 3, 4))
- # getattr(obj, attr, [default])
- print(getattr([1, 2, 3, 4], "len", 0))
- print(getattr([1, 2, 3, 4], "__init__"))
- # globals()
- print(globals())
- # hasattr(obj, name)
- print(hasattr("string", "__init__"))
- print(hasattr("string", "size"))
- # hash(obj)
- print(hash("string"))
- print(hash(10))
- print(hash(12345678910111213141516171819))
- # help([obj])
- import os
- help(os.system)
- help(complex)
- # hex(int)
- print(hex(100))
- print(hex(256))
- print(hex(12345678910111213141516171819))
- # id(obj)
- print(id("str"))
- print(id(0))
- # input([prompt])
- input("Enter a number: ")
- # raw_input([prompt])
- raw_input("Enter your name: ")
- # int([x, [base]])
- print(int("10"))
- print(int("abacaba", 13))
- print(int("10000", 2))
- # len(obj)
- print(len({1: 2, 3: 4, 5: 6}))
- print(len("str"))
- print(len([1, 2, 3, 4]))
- # locals()
- print(locals())
- # map(function, iterable)
- mapped = map(lambda x: (x ** 2) - 1, [0, 1, 2, 3])
- for var in mapped:
- print("[", var, "]")
- # max()
- print(max([4, 3, 2, 7, 1, 5, 6]))
- print(max(4, 3, 2, 7, 1, 5, 6))
- print(max('foo','xyz','abc','woo'))
- # min()
- print(min([4, 3, 2, 1, 5, 6, 7]))
- print(min(4, 3, 2, 1, 5, 6, 7))
- print(min('foo','xyz','abc','woo'))
- # oct(int)
- print(oct(10))
- print(oct(8))
- print(oct(124124))
- # ord(ch)
- print(ord('a'))
- # pow(x, y, [z])
- print(pow(2, 8))
- print(pow(2, 8, 3))
- # range(start, [stop, [step]])
- print(range(3))
- print(range(3, 7))
- print(range(3, 7, 2))
- # round(x, [num])
- print(round(0.55))
- print(round(0.535353535, 4))
- print(round(0.535353535, 3))
- # slice(start, [stop, [step]])
- print(slice(3))
- print(slice(3, 7))
- print(slice(3, 7, 2))
- # sorted(iterable, [key, [reverse]])
- print(sorted([1, 4, 2, 6, 8, 3, 1]))
- print(sorted([1, 4, 2, 6, 8, 3, 1], reverse=True))
- print(sorted(['123','xyz','abc',123,'*','-']))
- # str()
- print(str(1))
- print(str(0o123))
- print(str(0b100))
- print(str([1, 2, 3, 4]))
- # sum()
- print(sum([1, 2, 3, 4, 5, 6]))
- # type(obj)
- print(type("str"))
- print(type({1: 2}))
- print(type(2))
- print(type(1 + 3j))
- print(type(range(1, 3)))
- # zip(iterable)
- zipped = zip([1, 2, 3], [4, 5, 6])
- for pair in zipped:
- print("{", pair, "}")
- '''[1:-1]
- py2x=py2x.split('\n\n')
- def testrun(demo):
- for i in demo:
- if '#' in i: print '_'*30+'\n'
- print i
- print
- try:
- exec(i)
- except:
- print '!!! Invalid Entry !!!'
- print
- print
- #
- testrun(py2x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement