Python 是最优雅的语言,没有之一
她的优雅体现在 :、TAB 上
有多少次 if() 后忘记了:
有多少次 TAB缩进错误出现BUG :)
Python 不一样的地方
注释
# 行注释和shell一样
'''
多行注释
'''
"""
多行注释
"""
str 、list 、tuple、dict 等类型的长度
对于JS来说,就是上面的这些类型名字引用length属性
BUT Python不是
d={'green':1,'red':2}
len(d)//2
有一个函数len()
在字符串或者数组等其他数据类型末尾添加一个元素
对于JS来说是push()
d=[1,2,3]
d.append(4)
Python多了好多的方法对于数组?列表?
index()
insert()
del name[index]
Python没有自加加or自减减
a=1
a+=1
只能这样
多维列表
JS语言 是可以引用超出长度的,只不过undefine
list=[[],[],[]]
这样之后才可以引用
list[2]
if list=[] 是不能 list[2] indexerror
不过可以list.appen()
读写文件
with open('filename','r | w+ ') as:
- open ways is different
流程控制
if():
elif :
else:
Python 这朵奇葩
注意TAB!注意TAB!注意TAB!