class Animal(object):
__age = 2
def __init__(self, name, age):
self.name = name
cat = Animal('Kitty', '3')
print(cat.name)
print(cat._Animal__age)
__age = 2
def __init__(self, name, age):
self.name = name
cat = Animal('Kitty', '3')
print(cat.name)
print(cat._Animal__age)
2022-08-08
最贊回答 / 土斤土斤
這是一種代碼簡(jiǎn)寫的方式,稱之為推導(dǎo)式,是通過一行代碼完成循環(huán)判斷,并遍歷出一系列數(shù)據(jù)的編寫代碼方式。語(yǔ)法為:成員 for 循環(huán) ... if 判斷 ...而例子中的是為推導(dǎo)式中的一種類型,為列表推導(dǎo)式,結(jié)果是一個(gè)列表:?[item for item in Iterable]所以 result = [item for item in map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9])] 是這一段的簡(jiǎn)寫:result = []for i in? map(lamb...
2022-07-31
最贊回答 / weixin_慕萊塢3215187
class?Person(object): ????def?__init__(self,?name,?gender,?**kw): ????????self.name?=?name ????????self.gender?=?gender ????????for?k,?v?in?kw.items(): ????????????setattr(self,?k,?v) p?=?Perso...
2022-06-24
最新回答 / 土斤土斤
**kw是可變關(guān)鍵字參數(shù),可以理解為這是一個(gè)可變關(guān)鍵詞參數(shù)的字典dict,dict的items方法會(huì)返回dict中的所有元素,dict.items()=(key:value)
2022-05-18
import requests
response = requests.get('http://idcbgp.cn')
content = str(response.content, encoding='utf-8') # ==> 打印具體內(nèi)容
# print(content)
content_list = content.split('\n')
print(len(content_list))
for line in content_list:
if 'www' in line:
print(line.strip())
response = requests.get('http://idcbgp.cn')
content = str(response.content, encoding='utf-8') # ==> 打印具體內(nèi)容
# print(content)
content_list = content.split('\n')
print(len(content_list))
for line in content_list:
if 'www' in line:
print(line.strip())
2022-05-13
命令行:python -m http.server --bind 127.0.0.1 8000
py代碼:
import requests
response = requests.get('http://127.0.0.1:8000/')
# 打印狀態(tài)碼
print(response.status_code)
# 打印回應(yīng)頭
print(response.headers)
py代碼:
import requests
response = requests.get('http://127.0.0.1:8000/')
# 打印狀態(tài)碼
print(response.status_code)
# 打印回應(yīng)頭
print(response.headers)
2022-05-13