0% found this document useful (0 votes)
12 views

Python CCC101

Uploaded by

Firedehom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Python CCC101

Uploaded by

Firedehom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python-CCC101 s=s*3 def add(a,b): l.

pop()
return a+b l.pop(index)
Env Special chars: \n Build-in function l.clear()
pycharm list(), tuple(), set(), join: l+[3,4]
Preformat: dict() copy: l2 = l[:]
Debugging skills:
s=””” convert:
1. print l.sort(reverse=True)
hello list1=list(str)
2. Breakpoint, step over/ l.reverse()
world “,”.join(iterable)
step into/step out
”””
Long line: \ sorted(xxx, reverse=True) Set: Unique, no order, no
Short cut: reversed()
Find action: Ctrl-shift-A indexing/slicing: position
Run: Ctrl-r s[1], s[-1], s=set()
s[0:3], s[0:100] len() s1={1,2}
Debug: Ctrl-t
s[0::2], s[::-1] # range Add: s.add(‘one’)
Comments range(start,stop,step)
#, “”” delete:
# split # math s.remove(‘a’)
c1,c2='a b'.split() max(), min(), sum(), abs() s.discard(‘a’)
Variable Turtle s.pop()
x=100 # replace
s=str.replace(“a”, “A”) t=turtle.Turtle() s.clear()
del x ……
s=str.replace(“a”,’’) #
# convert type delete chars Iterable(Collection) Dictionary
type(var) # format List: d={}
int(), float(), str(), print(‘100’.zfill(10)) list1=[] d={‘key’:’value’}
bool() # query list1=[1,”a”,True] read: d[‘key’]
b=str.startswith(‘a’) nested_list=[1,2,3,[4,5]] d.keys(), d.values(),
Input
i = input() b=str.endswith(‘a’) d.items()
str.count(“a”) read:
Output list1[1], list1[-1] update: d[‘key’]=”three”
‘abc’.find(‘a’)
print(“hello”, end=’’, nested_list[3][1]
‘abc’.index(‘a’)
sep=’’) l[2:5]
# case Add:
str.lower() l[:2], l[1:],l[::-1] d[‘non_exist_key’]=100
‘%.2f” % 123.456
str.upper() query:
Data types 1 in list
Statement delete: del d[3]
Number 1 not in list
If, elif, else d.pop(key)
+, -, *, /, //,**, %, += list1.index(“a”)
for c in iterable: d.popitem() # LIFO
pass list1.count(“a”)
query: ‘key’ in dict1
Boolean: True, False
==, !=, >, >=, <, <=,
copy: d1=dict()
while True: update: list1[1]=”two”
not pass
or, and Add:
Random
in, not in import random
break, continue l.append(1)
random.randint(a,b)
nested loop l.extend(another_list)
a<b<c<d (a<=x<=b)
l.insert(index, “a”)
random.choice(‘abc’)
String ternary: “A” if condition delete: random.shuffle(list)
s = “hello” else “B” del l[2]
“abc”+”def” Functions l.remove(“a”)
Teens Programming

You might also like