Python笔记
RegulusF
这个作者很懒,什么都没留下…
展开
-
[python笔记]数据可视化
1.绘制折线图使用matplotlib绘制一个简单的折线图,使用平方数1,4,9,16,25绘制这个图表import matplotlib.pyplot as pltinput_values = [1, 2, 3, 4, 5]squares = [1, 4, 9, 16, 25]plt.plot(input_values, squares, lw = 5)"""plt.plot(...原创 2020-04-18 17:28:40 · 255 阅读 · 0 评论 -
[python笔记]alien_invasion
alien_invasion.pyimport sysimport pygamefrom pygame.sprite import Groupimport game_functions as gffrom alien import Alienfrom settings import Settingsfrom ship import Shipfrom game_stats imp...原创 2020-04-17 19:16:36 · 553 阅读 · 0 评论 -
[python笔记]八.类
一.创建和使用类1)创建类eg:class Dog(): def _init_(self, name, age): self.name = name self.age = age def sit(self): print(self.name.title() + "is now sitting.") def roll_ov...原创 2020-01-31 19:38:27 · 129 阅读 · 0 评论 -
[python笔记]7.函数
一.定义函数1)def使用关键字def定义函数,后面跟函数名,括号中为参数,以冒号结尾,后面的缩进行为函数体,eg:def greeter_user(): print("hello world")greeter_user()输出:hello world二.给函数传递参数1)位置实参eg1:def great_user(user_name): '''显示其简...原创 2020-01-31 13:17:20 · 215 阅读 · 0 评论 -
[python笔记]6.用户输入和while循环
一.input()函数1)input()input接受一个参数,向用户显示的提示说明,输入存储在变量中eg1:message = input("Tell me something, and I will repeat it back to you: ")print(message)输出Tell me something, and I will repeat it back to y...原创 2020-01-30 19:23:51 · 136 阅读 · 0 评论 -
[python笔记]5.字典
一.字典字典可以将相关的信息关联起来aline_0={'color':'green','points':5}print(aline_0['color'])print(aline_0['points'])输出green5二.使用字典字典是一系列的键-值对,每个键都与一个值想关联,可以使用键来访问想关联的值,与键值相关的值可以是数字,字符串,列表或者字典,可以将任何对象用作字典中...原创 2020-01-29 10:22:45 · 223 阅读 · 0 评论 -
[python笔记]4.if语句
一.示例cars=['audi','bmw','subaru','toyota']for car in cars: if car=='bmw': print(car.upper()) else: print(car.title())输出AudiBMWSubaruToyota二.条件测试1)检查是否相等>>>...原创 2020-01-28 16:34:04 · 96 阅读 · 0 评论 -
[python笔记]3.列表
1.访问列表元素1)基本访问方式bicycles=['trek','cannondale','redline','specialized']print(bicycles)#输出列表中的所有元素print(bicycles[0])#按索引访问print(bicycles[0].title())#列表中元素调用方法输出['trek', 'cannondale', 'redline', ...原创 2020-01-16 18:34:56 · 318 阅读 · 0 评论 -
[python笔记]2.数字
1)整数1)加减乘除 乘方(**)组合运算>>> 2+35>>> 3-21>>> 2*36>>> 3/21.5>>> 3**29>>> 3**327 >>> 2+3*414 >>> (2+3)*420 二:浮点数...原创 2020-01-16 10:45:07 · 111 阅读 · 0 评论 -
[python笔记]1.字符串
一.使用方法修改字符串大小写1)首字母大写 title():每个单词的首字母都改为大写name="ada lovelace"print(name.title())输出Ada Lovelace2)字符串全部大写 upper()/字符串全部小写 lower()name="ada lovelace"name=(name.title())print(name.upper())pri...原创 2020-01-16 10:33:04 · 90 阅读 · 0 评论