String format
txt = '{:>30}'.format(word) //right side
txt = '{:<30}'.format(word) //left side
txt = '{:^30}'.format(word) //center
txt = "tessttt"
txt.center(16,'-') //center
txt.ljust(16,'-') //left side
txt.rjust(16,'-') //right side
Check Character in String
A = "this is tesst"
for num in range(0,len(A)):
print (A[num])
if A[num] in B:
count_same = count_same + 1
List
In & not in
if "test" in list_a
print('true')
if "game" not in list_a
print('false')
append & extend & remove
Dictionary
key กับ value
empty_dict = {}
url = 'http://www.google.com/'
res = 'None'
empty_dict ={url: res}
print(empty_dict)
print(empty_dict[url])
print('Name: ', empty_dict.get('http://www.google.com/'))
empty_dict.clear()
update() & copy()
items() & keys() & values()
get() & setdefault(key,value)
Nested Dictionaries
Tuple
ไม่สามารถแก้ไขข้อมูลได้
test = ("apple", "banana", "cherry")
Set
s = {[35,'asdas','game']}
add & update
s.add('game')
remove() & discard()
pop() & clear()
copy() & union()
intersection() & intersection_update()
difference() & difference_update()
symmetric_difference() & symmetric_difference_update()
สร้าง set ที่ไม่ซ้ำกัน