#temp 1
print("#################### temp 1 ####################")
total_number = oneTwoThree = 1
x1 = 1
__main__ =1
print(total_number, oneTwoThree, id(total_number), id(oneTwoThree))
print (x1, id(x1))
x1 = "hello"
print(x1,id(x1))
def a():
'''hello
abcdabcd'''
pass
help(a)
x = y = total_number = oneTwoThree = 1
print(total_number, oneTwoThree, x, y)
#del x
print(total_number, oneTwoThree, x, y)
x = 1
y = 1.0
z = 1+1j # class 'complex'
i = "abc"
j = True
print(type(x), type(y), type(z), type(i), type(j))
print(0.5-0.4)
print(0.1+0.1+0.1)
#temp 2
print("#################### temp 2 ####################")
print("########## temp 2 ##########")
from decimal import Decimal
print(Decimal("0.5") - Decimal("0.4"))
print(type(0.1))
x = 10**100 # 1 followed by 100 zeros
print(x)
print(type(x)) # Still <class 'int'>
print(("hello".upper().lower().title() * 3).capitalize().isalnum())
#temp 3
print("#################### temp 3 ####################")
name = "john"
age = 10
# case 1 place holder codes %s string, %d integer %f float %x hex
#print("Name : %s, Age : %s" % (name, age))
print("Name : %s, Age : %d" % (name, age))
# case 2 convert data to str
print("Name : " + name +", Age : " + str(age))
# case 3 str.format()
print("Name : {}, Age : {}, Name again : {}".format(name, age, name))
# case 4 named arguments
print("Name : {n}, Age : {a}, Name again : {n}".format(n=name, a=age))
# eg.
print("Double {x}: {x} + {x} = {sum_x}".format(x=5, sum_x = 5 + 5))
# case 5 : f-string python > 3.6
print(f"Name : {name}, Age : {age}, Name again : {name}")
x = 5
sum_x = 5+5
print(f"Double {5}: {5} + {5} = {5+5}")
print(f"Double {x}: {x} + {x} = {sum_x}")
print("#################### temp 4 ####################")
name = "john"
age = 10
#format numbers
price = 49.99
tax = 0.08
total = price * (1 + tax)
print(f"Price : ${price:.2f} | Tax : {tax:.1%} | Total: ${total:.2f}")
## f"{variable:[fill][align][width][.precision][type]}
print(f"{age:5d}")
print('1---5----01---5----0')
print(f"{'Name':<10}{'Age':>5}") # < left align, > right align ^ center
#print(f"{name:$<10}{age:->5.2f}")
print(f"{name:<10}{age:->5.2f}")
print(f"{name:<10}{age:->5d}")
print(f"{name:<10}{age:->10.2f}")
print(f"{name:<<10s}{age:->10.2f}{' ':$<10}")
print(f"{'Apple':^10}")
#1---5----01---5----0
#Name Age
#john 10
# Apple
print(f"{42:05}")
print(f"{42:0<5}")
print(f"{1234567:,}")
print(f"{42:5b}") # binary value
print(f"{42:5o}") # octal value
print(f"{42:5x}") # hex value
# scu firnat
print(f"{42:5e}") # value in e format
print(f"{42:5E}") # value in E format
print(f"{13.14564567:.5g}") # 5 sig figure
print(f"{11113.14564567:.5g}") # 5 sig figure
print(f"{1113.14564567:.5g}") # 5 sig figure
print(f"{111113.14564567:.5g}") # 5 sig figure
print(f"{111113.14564567:.5G}") # 5 sig figure
print(f"{0.14122143:.5%}") # 5 sig figure
print("#################### temp 5 ####################")
#print(True, False, type(True))
#print(False == 0)
x = True and 2 and [1] and {0} and -1.0 and "hello" # truthy value
print(x)
y = False or 0 or [] or {} or None or 0.00 or ' ' # falsy value
print(y)
#print(print(" "))
#==========================================
default_city = 'kw'
city = ''
city = city or print("please input city") or default_city
print(city)
print("#################### temp 6 ####################")
name = ["john", "ann", "mary", "peter", ["ryan", 1], 2, 3, [True, 0,0,9, "hello"]]
print(name, id(name), type(name))
print(name[0], name[4])
print(name[4][0])
name[0] = ["david", 20]
name[4][0]= 'goodman'
print(name)
del name[1]
print(name)
print("#################### temp 7 ####################")
a=[1,[2,3],4,5,6,7,8,9,['a','b','c']]
print(a[8][1])
a=[1,[2,3],4,[5,[[6],7]],8,9,['a','b','c']]
print(a[3][1][0][0])
a[0] = 10
print(a)
a[1] = 10
print(a)
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
print(a[10], a[-4])
b=slice(0,7,1) # start, end-1, step
print(type(b))
print(a[b], a[0:7:1])
print(a[b], a[0:15:7])
x = 2
y = 17
z = 6
b = slice(x,y,z) # start, end-1, step
print("aaa")
print(a[x:y:z])
print("bbb")
print(a[7:2:1])
print(a[7:-1:1])
print(a[7:-1:-1])
print("ccc")
print(a[-1:0:-4])
print(a[15:0:-4])
#allow empty value and some functions
print(a[-1::-1])
print(a[:10]) # 0:10:1
print(a[::5]) # 0:len(a):5
print(a[0:15:1])
print("ddd")
del a[::5]
print(a)
a.remove(4)
print(a)
a = [1,2,3,4,5,4,6,7,8,9,10,11,12,13,14,15,16]
a.remove(4)
print(a)
a.clear()
print(a)
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
a = []
print(a)
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
a.sort(reverse=True) # change original list
print(a)
print("eee")
b = sorted(a)
print(a)
print(b)
print("fff")
a=[1,2,3,4,9,10,11,12,5,6,7,8,13,14,15]
a.sort()
print(a)
b = sorted(a,reverse=True)
print(a)
print(b)
a=[1,2,3,4,9,10,11,12,5,6,6,7,8,13,14,15]
print(a.count(6), a.index(6))
print(a.count(0), a.index(6))
#print(a.count(0), a.index(0)) #error appear for index 0 not in the list
print("#################### temp 8 ####################")
#temp 8, for tuple
a = 1,2,3,4,9,10,11,12,5,6,6,8,13,14,15
print(a.count(0),a.index(6))
print(a[0])
#a[0]=10
#a.sort()
print(a)
b = sorted(a,reverse=True)
print(a)
print(b)
b = 1,
print(b)
b = ()
print(b, type(b))
a = {1,2,"a",3,4,"",9,10,"b",11,12,5,6,"a",6,8,13,14,15}
print(type(a))
print(a)
print("ggg")
a = [1,2,"a",3,4,"b",9,10,"b",11,12,5,6,"a",6,8,13,14,15]
#a = set(a)
#print(type(a))
#a = list(a)
a = list(set(a))
print(a)
a = {1,2,"a",3,4,"",9,10,"b",11,12,5,6,"a",6,8,13,14,15}
a.add(16)
print(a)
a.update(a, {17, 18})
print(a)
a = {1,2,3,4}
b = {3,4,5,6}
print(a | b)
print(a & b)
print(a - b)
print(a ^ b)
print("#################### temp 9 ####################")
#temp 9
print("Hello \
World!")
print('''Hello
Wor
ld!''')
a = (1,
1+1 )
print(a, type(a))
if 1:
x = 1
y=1
print("#################### temp 10 ####################")
#temp 10
name = 'name'
d = {'name' : "john", # 'name' = "john"
"age": 10+1,
}
print(d['name'])
print(d['age'])
name = 'age'
print(d['name'],d['age'])
print(d[name])
d = {"name" : "john",
"age": 10+1,
True : 12,
(1,2): 30,
}
name = 'age'
print(d[name])
print(d[(1,2)], d[True], d)
print("#################### temp 11 ####################")
#temp11
c = a = [1,2,3]
b = [1,2,3]
print(id(a), id(c), id(b))
print(id(a[0]), id(c[0]), id(b[0]))
d = {"name" : "john",
"age": 10,
"gender" : "male"
}
del d["gender"]
print(d)
d["name"] = "peter"
print(d)
d["mame"] = "prince building"
print(d)
print(d.keys())
for i in d.keys():
print(i)
print(d.values())
print(d.items())
print("#################### temp 12 ####################")
#temp 12
#NO 1
result = 7 - 4 + 3 * 6 / 2 ** 2 % 5
print ('01', result)
result = ((7 - 4) + (((3 * 6) / (2 ** 2)) % 5))
print ('01', result)
#NO 2
result = 12 - 2 * 5 > 3 and 8 % 5 == 3 or not 4 + 1 > 7
print ('02', result)
result = (((12 - (2 * 5)) > 3) and ((8 % 5) == 3)) or (not ((4 + 1) > 7))
print ('02', result)
print("#################### temp 13 ####################")
#temp 13
def a(x, y, z=2):
result = x + y + z
print(f"result = {result}")
print("x =", x, "y =", y, "z =", z)
print(f"x = {x} y = {y} z = {z}")
return result
print(a(3, 4))
result = a(y=4,z=5,x=6) + a(7,8,9)
print(result)
print(globals())
print(a('a', 'b', 'c'))
print(a("john"," ", "lee"))