python基础学习
菩提树下的承诺
人生苦短,我用python
展开
-
python14day
-- coding=utf-8 --文件test_1 = open(‘alice.txt’, ‘a’)test_1.write(“hello 123”)test_1.write("\nword")test_1.close()test_1 = open(r’alice.txt’)test_1.read()print(test_1.read(3))yield生成器def foo()...原创 2019-03-13 15:26:36 · 187 阅读 · 0 评论 -
python13_1day正则表达式
re正则表达式通配符.对特殊字符进行转义\字符集[a-z]匹配其中的任意字符,[^a]匹配除a以外的其它字母选择符和自模式管道符号(|),匹配’python|perl’‘p(ython|erl)’可选项和重复子模式在子模式后面加上问号,它就变成了可选项r’(http:\)?()*重复0次或多次()+重复1次或多次(){m,n}重复m~n次import rere.compi...原创 2019-03-13 15:26:23 · 188 阅读 · 0 评论 -
python13day
#############import sys, pprintsys.path.append(‘D:/pycharm_work’)import day_7dir(day_7)import hell4hell4.hello()pprint.pprint(sys.path)#查找模块位置import copyprint(dir(copy))#dir查看模块内容print([n fo...原创 2019-03-13 15:26:06 · 139 阅读 · 0 评论 -
python12_1day
class TestIterator:value = 0def __next__(self): self.value += 1 if self.value > 10: raise StopIteration return self.valuedef __iter__(self): return selfti = TestIterator()pri...原创 2019-03-13 15:25:47 · 187 阅读 · 0 评论 -
python12day
私有属性_xclass Rectangle:def init(self):self.width = 0self.height = 0def setSize(self, size): self.width, self.height = size # 使两个值都等于sizedef getSize(self): return self.width, self.height...原创 2019-03-13 15:25:23 · 156 阅读 · 0 评论 -
python11day
菲波那契数列fibs = [0, 1]num = int(input("how many fibonacci numbers do you want? "))for i in range(num - 2):fibs.append(fibs[-2] + fibs[-1])print(fibs)def init(data):data[‘first’] = {}data[‘middle...原创 2019-03-13 15:24:45 · 164 阅读 · 0 评论 -
python10_1day
x=input(“x:”)y=input(“y:”)#input假设用户输入的是标准表达式,print(int(x)*int(y))print(pow(2, 3))from math import sqrtimport cmathprint(sqrt(8))print(cmath.sqrt(-1))print(repr(“hello word”)) # 以合法的形式表达值pri...原创 2019-03-13 15:24:31 · 206 阅读 · 0 评论 -
python10day
def test(num):print(“在函数内部%d对应的地址是%d” % (num, id(num)))result = “hello”print(“函数要返回的内存地址是%d” % id(result))return numa = 10print(“a变量的数据存储地址是%d” % id(a))r = test(a)print("%s的内存地址是 %d" % (r, id®...原创 2019-03-13 15:24:15 · 145 阅读 · 0 评论 -
python9_1day
-- coding=UTF-8--import jsonusername = input(“what is your name?”)filename = ‘username.json’with open(filename, ‘w’) as f_obj:json.dump(username, f_obj)print(“we’re rember you,when your back " +...翻译 2019-03-13 15:23:47 · 211 阅读 · 0 评论 -
python9day分析文本
分析文本title = “Alice in Wordlad”title.split()filename = ‘alice.txt’try:with open(filename) as f_obj:contens = f_obj.read()except FileNotFoundError:msg = “Sorry,the file " + filename + " does not...翻译 2019-03-12 18:22:12 · 138 阅读 · 0 评论 -
python8day
-- coding=utf-8 --from day_7 import Car,Electricarmy_new_car=Car(‘audi’,‘a4’,2016)print(my_new_car.get_description_name())my_new_car.odometer_reading=23my_new_car.read_odometer()my_tesla=Electr...翻译 2019-03-12 18:14:51 · 117 阅读 · 0 评论 -
python7day
class Car( ):“”“一次模拟汽车的尝试”""def init(self,make,model,year):#初始化描述汽车的属性self.make =makeself.model = modelself.year = yearself.odometer_reading=0def get_description_name(self):#返回整洁的描述性信息long...翻译 2019-03-12 18:12:49 · 92 阅读 · 0 评论 -
python6day
def greet_user(username,man):#username是形参print(“hello!”+username+ ’ ‘+man)greet_user(‘yang’,‘n’)#yang是实参def describe_pets(pet_name,animal_type=‘dog’):print("\nl have a "+’ ‘+animal_type+’ ‘+pet_na...翻译 2019-03-12 18:11:38 · 132 阅读 · 0 评论 -
python5day
#continue的用法current_number=0while current_number<10:current_number+=1if current_number %2==0:continueprint(current_number)#在列表之间移动元素unconfirmed_users=[‘alice’,‘brian’,‘candace’]confirmed_u...原创 2019-03-12 18:09:57 · 104 阅读 · 0 评论 -
python4day
message=’’active =Truewhile active:message=input(“quit”)if message ==‘quit’:active=Falseelse:print(message)while True:city=input(“lanzou”)if city == ‘quit’:breakelse:print(“l would love ...原创 2019-03-12 18:08:55 · 75 阅读 · 0 评论 -
python3day
#字典alien_0={‘color’:‘green’,‘points’:5}print(alien_0[‘color’])alien_0[‘x_postion’]=0alien_0[‘y_postion’]=25#添加键-值对print(alien_0)alien_1={}alien_1[‘color’]=‘green’alien_1[‘points’]=5print(alie...原创 2019-03-12 18:07:34 · 104 阅读 · 0 评论 -
python2day
for value in range(1,5):print(value)numbers=list(range(1,6))#生成列表print(numbers)squares=[]for value in range(1,11):square=value2squares.append(square)print(squares)print(min(squares))print(ma...原创 2019-03-12 18:05:53 · 76 阅读 · 0 评论 -
python14——2day网络服务器
网络小型服务器import sockets = socket.socket()host = socket.gethostname() # 获取主机名port = 1234s.bind((host, port))s.listen(1) # 监听给定的地址while True:c, addr = s.accept() # 等待下一个连接print(‘got connectio...原创 2019-03-13 15:26:52 · 139 阅读 · 0 评论