- 博客(9)
- 收藏
- 关注
原创 day 8 python 从入门到实践——测试代码
测试单个函数——使用到unittest模块import unittestfrom name_function import get_formatted_nameclass NamesTestCase(unittest.TestCase): #类的继承 """测试name_function.py""" def test_first_last_name(self): ...
2020-04-23 00:28:57
83
原创 Day 8 python 从入门到实践——文件与异常
读取整个文件with open("pi_digits.txt") as file_object: #此处pi_digits.txt文件位于正在编辑的py文件同目录文件夹内 contents = file_object.read() print(contents.rstrip())简单使用读取文件#文件路径#相对路径# with open(r'text_files...
2020-04-22 18:24:06
88
原创 Day 7 python 从入门到实践——类
类——一大类对象的通用行为或属性,根据实际对象可以调整创建Dog 类class Dog(): def __init__(self,name,age): """初始化属性name和age""" self.name = name self.age = age def sit(self): """模拟小狗被命...
2020-04-21 17:52:59
93
原创 Day 6 python 从入门到实践——函数
定义函数#定义函数def greet_user(): """显示简单问候语""" print("Hello")greet_user()#向函数传递信息def greet_user(user_name): """显示简单问候语""" print("Hello "+user_name.title()+" !")greet_user("Li lei")...
2020-04-21 14:29:32
82
原创 Day 6 Python 从入门到实践——用户输入与while循环
接受用户输入 input()函数message = input("Tell me something , and i will repeat it back to you :")print(message)获取数值输入——默认input()将用户输入处理为字符串age = input("How old are you? :")print(age)age = int(age)#...
2020-04-20 17:30:41
77
原创 Day 5 Python 从入门到实践:字典
字典 ——一系列键值对alien_0={"color": "green"}#"color"为键,"green"为与之对应的值print(alien_0["color"])访问字典中的值alien_0={"color": "green", "points": 5}new_points = alien_0["points"]print("You just earn "+str(...
2020-04-19 15:52:31
87
原创 Day four Python 入门到实践
if 语句简单示例cars=["audi","bmw","subaru","toyota"]for car in cars: if car=="bmw": print(car.upper()) else: print(car.title())不相等 !=requested_topping="mushrooms"if requested_topping != "an...
2020-04-18 23:41:33
111
原创 day3 python入门到实践——遍历整个列表
magicians=["alice","david","carolina"]for magician in magicians: print(magician) print(magician.title()+" ,that was a great trick") print("I can't wait to see you next trick, "+magician.title()...
2020-04-18 01:05:23
93
原创 Python入门到实践:day two
列表一系列按照特定顺序排列的元素组成。bicycles=["trek","cannondable","redline","specialized"]print(bicycles)访问列表元素bicycles=["trek","cannondable","redline","specialized"]print(bicycles[0])#访问列表第一个元素print(bicy...
2020-04-16 18:46:33
82
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人