我是python(來自C++世界)的新手,正在嘗試使用類方法。我創建了一個沒有任何參數的方法(在這種情況下有目的地避免了self參數)。然後我試圖把它 class car:
def car_method():
print("Inside Car method")
obj = car_method()
obj.car_method() <---- this creat
def duplicate_count(s):
return len([c for c in set(s.lower()) if s.lower().count(c)>1])
我很難理解這段代碼的工作原理。我正在做一個codewars挑戰,以返回字符串中重複元素的數量。 例如。 Asasd - > 2 我想出了我自己的暗示,但我無法真正理解這段代碼的作用。如果有人可以指出我的方向,它
program1.py: a = "this is a test"
for x in a:
print(x)
program2.py: a = """this is a test
with more than one line
three, to be exact"""
for x in a:
print(x)
program3.py: im