1. 使用縮進方式做為程式塊開始結束的標示,程式換行在行末尾加 "\"

2. 元祖(Tuple)數據類型,和List的不同是Tuple不能修改,優點是執行速度比List快,因為不能修改也就比較安全,團隊開發某些情況會用到。

3. Dict字典類型,若鍵有重複時,後面的建值會覆蓋掉前面的。

dict = {"banana": 20, "apple": 30, "orange": 40, "banana": 30}
print(dict["banana"]) #30

字典類型的排列順序是隨機的,與設定的順序不一定相同,所以在讀取時就不能使用index。

dict = {"banana":20, "apple": 30}
result = dict.items() # 取得以[鍵:值]為組合的Array
# [("banana":20), ("apple":30)]
result = dict.setdefault("apple", 50) #
result = dict.setdefault("orange", 80) # create new
fruits = ["apple", "mango", "orange"] #list
numbers = (1, 2, 3) #tuple
alphabets = {'a':'apple', 'b':'ball', 'c':'cat'} #dictionary
vowels = {'a', 'e', 'i' , 'o', 'u'} #set

4. python3 內建了SQLite, 非常方便储存數據,不需要再額外設定database環境

5. pyhon class 的 structure function.

class Person:
def __init__(self, name, age):
self.name = name
self.age = age def myfunc(self):
print("Hello my name is " + self.name) p1 = Person("John", 36)
p1.myfunc() # the function called __init__(), which is always executed when the class is being initiated. # Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created # The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class. # It does not have to be named self , you can call it whatever you like, but it has to be the first parameter of any function in the class

6. string join

sentence = ['this','is','a','sentence']
'-'.join(sentence)
# this-is-a-sentence

7. function as function argument

def Calculate(func, *args):
print(func(*args)) def Add(arg1, arg2):
return arg1 + arg2 def Sub(arg1, arg2):
return arg1 - arg2 Calculate(Add, 1, 3) #
Calculate(Sub, 1, 3) # -1

另外還有一種 keyword argument的用法,Calulate(func, **keywordArgs)

最新文章

  1. vagrant 1.8.6 安装过程及总结遇到的坑
  2. php面向对象编程(二)
  3. linux下常见的字符串处理
  4. 【PHP面向对象(OOP)编程入门教程】3.什么是面向对象编程呢?
  5. 精通AngularJS 读书笔记(1)
  6. Selenium2+python自动化15-select下拉框
  7. Python:print显示颜色
  8. 读取本地Json文件
  9. MVC系列之二 Model层细解
  10. dialog参数、方法以及事件
  11. 0128——手势Gesture
  12. NET基础课--代码安全
  13. JavaScript 运动框架 Step by step
  14. Runtime.exec使用错误导致延迟.md
  15. juery悬浮框
  16. java学习笔记06-条件语句
  17. SpringBoot系列: Web应用鉴权思路
  18. 固态硬盘的PCIE,SATA,M2,NVMe,AHCI分别都指什么?别再搞混了
  19. 微服务-注册与发现-zookeeper bydasn
  20. 利用STM32CubeMX来生成USB_HID_host工程

热门文章

  1. python应用-一组数的最大值,最小值,平均数
  2. Ofbiz项目学习——阶段性小结——视图
  3. Dart编译技术与平台
  4. js 对小数进行格式化(保留小数,去除小数后的0)
  5. Java验证jwt token
  6. Numpy | 14 字符串函数
  7. 52: Luogu 4777 excrt
  8. 求等差数列前$n$项和$S_n$的最值
  9. 内置函数— — eval、exec、compile
  10. 拼图验证码 js,vue