Please enable JavaScript.
Coggle requires JavaScript to display documents.
PYTHON - Coggle Diagram
PYTHON
Python Object and Data Structure
Number
Integer: int
Float: float
Variable
use lowcase, underscore
Dynamic Tying: reassign variable to difference data type
Pros: Easy to work, faster development time
Cons: Bugs for unexpect data type, use type() to check
String
single/ double quote,
order sequence : indexing, slicing, reverse indexing
Format
'hello {value:width.precision}'.format()
print(f'hello')
slicing: [start:stop:step]
len(str)
Immuable: can't change
LIST['chi',23,12.123,True]
ordered sequence, hold a variety of object type
Muable
Dictionaries('key':value)
Unordered mapping for store object
Key-Value
Muable
items(), keys(), values()
Tuple()
Similar List , Immuable
Set
Unordered, Unique
convert List -> Set
Bool
File
open()
read(): only read once
Statements
If elif else
For loop
For item in lst:
While loop
while/else
break, continue, pass
For i in range(10):
list(range(2,10,2))
For index, letter in enumerate(word):
zip(lst1, lst2)
'x' in ['x', 'y', 'z']
input(): receive a string
List Comprehension: [ x if x%2 == 0 else 'ODD' for x in range(10) ]
Method and Function
*args
pass a tuple()
**kawargs
pass a dict{}: key -> value
def func(
args, *
kwargs):
Function Programing
Map
Lambda
Filter
Reduce
use the global keyword if want to change a global variable inside a function.
Modulde and Package
from MainPackage import mainscript
from MainPackage.Subpackage import subscript
Build in variable :
name
Operator
Comparition
Logical
and
or
not
OOP
NameOfClass
Error and Exception Handing
try/ except/ finally
Python Decorator
Generator