Python
18 Jul 2018Start
First line
# -*- coding: UTF-8 -*-
Numbers
int
like1
,20
float
like1.2
,20.123
complex
like1j
,20j
print(type(x)) # <class 'int'>
print(type(y)) # <class 'float'>
print(type(z)) # <class 'complex'>
Output
- Python2.x:
print x, y, z
- Python3.x:
print(x, y, z)
list vs tuple
Different between list and tuple is tuple is not changable.
function
def functionname([formal_args,] *var_args_tuple ):
# do something
def sum(num, *num_list):
sum = num
for element in num_list:
sum += element
print("sum=",sum)
sum(1)
sum(1,2,3,4)
file
model
r
reada
addb
bin+
read and write
cache
file = open('/path/to/file', 'a', cache=true)