# Enter a code
class Animal(object):
def __init__(self,name,age):
self.name = name
self.age = age
dog = Animal('dog',1)
cat = Animal('cat',2)
print(dog.name,dog.age)
print(cat.name,cat.age)
class Animal(object):
def __init__(self,name,age):
self.name = name
self.age = age
dog = Animal('dog',1)
cat = Animal('cat',2)
print(dog.name,dog.age)
print(cat.name,cat.age)
2022-08-31
# Enter a code
class Animal():
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
class Animal():
pass
dog = Animal()
cat = Animal()
print(dog)
print(cat)
print(dog == cat)
2022-08-30
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
import requests
response = requests.get('https://www.imooc.com')
content = str(response.content, encoding='utf-8') # ==> 打印具体内容
# 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('https://www.imooc.com')
content = str(response.content, encoding='utf-8') # ==> 打印具体内容
# 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/')
# 打印状态码
print(response.status_code)
# 打印回应头
print(response.headers)
py代码:
import requests
response = requests.get('http://127.0.0.1:8000/')
# 打印状态码
print(response.status_code)
# 打印回应头
print(response.headers)
2022-05-13
cmd中python -m http.server --bind 127.0.0.1 8000启动http服务器。
py文件中代码:
from urllib import request
response = request.urlopen('http://127.0.0.1:8000/')
print(response.status)
for k, v in response.getheaders():
print('{}: {}'.format(k, v))
py文件中代码:
from urllib import request
response = request.urlopen('http://127.0.0.1:8000/')
print(response.status)
for k, v in response.getheaders():
print('{}: {}'.format(k, v))
2022-05-13
这里是py2的环境,Person父类首先要继承object类,然后Student类的super方法也要传继承的子类和self两个参数才能调用__init__方法,py3的话父类不需要继承object类,spuer方法也不用传参就能直接调用
2022-05-09
class Person(object):
def __init__(self, name,age,location):
self.__name = name
self.__age=age
self.__location=location
def get(self):
return '{},{},{}'.format(self.__name,self.__age,self.__location)
p = Person('Alice',22,'hongkong')
print(p.get())
def __init__(self, name,age,location):
self.__name = name
self.__age=age
self.__location=location
def get(self):
return '{},{},{}'.format(self.__name,self.__age,self.__location)
p = Person('Alice',22,'hongkong')
print(p.get())
2022-04-23