日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

新手學python之新體驗

發布時間:2025/3/21 python 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 新手學python之新體驗 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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) # 30 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 = nameself.age = agedef 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 + arg2def Sub(arg1, arg2):return arg1 - arg2Calculate(Add, 1, 3) # 4 Calculate(Sub, 1, 3) # -1

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

?

轉載于:https://www.cnblogs.com/sipher/p/11437791.html

總結

以上是生活随笔為你收集整理的新手學python之新體驗的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。