x = 100
print(~x)
>> -101
x = 4
if x != 5:
print("x is not equal to 5")
import time
def tictoc(func):
def wrapper():
start = time.time()
func()
end = time.time()
print(f"{ func.__name__ } executed in { '{:.2f}'.format(end - start) } seconds")
return wrapper
@tictoc
def do_something_1():
print("Doing something 1")
time.sleep(2)
print("Done something 1")
@tictoc
def do_something_2():
print("Doing something 2")
time.sleep(3.5)
print("Done something 2")
do_something_1()
do_something_2()
x = 98
print(x%2, x%3, x%5, sep=" ___ ")
>> 0 ___ 2 ___ 3
print("x = %s" % x)
>> x = 98
a = 0b1111000010
b = 0b0000111110
x = a ^ b
print(bin(a), bin(b), bin(x), sep=" ___ ")
print(a, b, x, sep=" ___ ")
>> 0b1111000010 ___ 0b111110 ___ 0b1111111100
>> 962 ___ 62 ___ 1020
a = 0b00110011
b = 0b11110000
x = a & b
print(bin(x))
>> 0b110000
-
print(4 * 5) print(3 * "Hello ") >> 20 >> Hello Hello Hello
a, b, *others = (4, 5, 12, 4, 5, -2) print("a = %s, b = %s, others = %s" % (a, b, others)) >> a = 4, b = 5, others = [12, 4, 5, -2]
def say_hello(*args): print(args) say_hello("Choaib", 22, "ENSA") >> ('Choaib', 22, 'ENSA')
def say_hi(**kwargs): print(kwargs) say_hi(name="Choaib", age=22, school="ENSA") >> {'name': 'Choaib', 'age': 22, 'school': 'ENSA')
from module_name import *
a = 0b01010101
b = 0b10101010
x = a | b
print(bin(x))
>> 0b11111111
a = 0b110011
print(bin(a))
print(a)
# Left Shift === Multiplication by 2
print(bin(a << 1))
print(a << 1)
# Right Shift === Division by 2
print(bin(a >> 1))
print(a >> 1)