![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
Ys_sr
这个作者很懒,什么都没留下…
展开
-
Python学习笔记一
书籍Python编程入门到实践京东:https://u.jd.com/mxYv6z变量message = "Hello Python World"print(message) # 打印messagemessage是变量,讲字符型(string)‘Hello Python World’ 赋值给message ,然后使用print() 函数打印变message.变量命名规则:...原创 2020-03-24 11:09:25 · 111 阅读 · 0 评论 -
笨方法学Python 习题40
字典mystuff = {'apple': "I AM APPLE!"}调用print("mystuff['apple'])模块def apple(): print("I AM APPLE!")#另一个变量tangerine = "Living reflection of a dream"保存为 mys原创 2018-10-04 20:55:17 · 365 阅读 · 2 评论 -
笨方法学Python 习题25
def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef sort_words(words): """Sorts the words.""" return sorted(words原创 2018-09-27 16:35:47 · 443 阅读 · 0 评论 -
笨方法学Python 习题29
people = 20cats = 30dogs = 15if people < cats: print("To many cats! The world is doomed!")if people > cats: print("Not to many cats! The world is saved!")if people < dogs: ...原创 2018-09-28 09:08:51 · 111 阅读 · 0 评论 -
笨方法学Python 习题30
people = 30cars = 40buses = 15if cars > people: print("We should take the cars.")elif cars < people: print("We should not take the cars.")else: print("We can't decide.")if bu...原创 2018-09-28 09:45:55 · 166 阅读 · 0 评论 -
笨方法学Python 习题31
print("You enter a dark room with two doors. Do you go through door #1 or door #2?")door = input("> ")if door == "1": print("There's a giant bear here eating a cheese cake. What do you do?"...原创 2018-09-28 10:10:10 · 105 阅读 · 0 评论 -
笨方法学Python 习题32
#!usr/bin/python3# -*- coding:utf8 -*-the_count = [1,2,3,4,5]fruits = ['apples','oranges','pears','apricots']change = [1,'pennies',2,'dimes',3,'quarters']# this first kind of for-loop goes thro...原创 2018-09-29 19:21:15 · 145 阅读 · 0 评论 -
笨方法学Python 习题33
#!usr/bin/python3# -*- coding:utf8 -*-i = 0numbers = []while i &amp;lt; 6: print(&quot;At the top i is {0}&quot;.format(i)) numbers.append(i) i = i+1 print(&quot;Numbers now: &quot;, numbers)原创 2018-09-29 19:44:10 · 176 阅读 · 0 评论 -
笨方法学Python 习题35
#!usr/bin/python3# -*- coding:utf8 -*-from sys import exitdef gold_room(): print("The room is full of gold. How much do you take?") next = input('> ') if '0' in next or '1' in next...原创 2018-09-29 20:59:11 · 445 阅读 · 0 评论 -
Python 面向对象
面向对象编程—Object Oriented Programming, 简称OOP, 是一种程序设计思想。OOP把对象作为程序的基本单元,一个对象可以是数据,也可以是操作数据的函数。面向过程的程序设计把计算机程序视为一系列的命令集合,即一组函数的顺序执行。为了简化程序设计,面向过程把函数继续切分为子函数,即把大块函数通过切割成小块函数来降低系统的复杂度。而面向对象的程序设计把计算机程序视为一组...原创 2018-10-09 17:11:15 · 159 阅读 · 0 评论 -
笨方法学Python 习题42
#!usr/bin/python3# -*- coding:utf8 -*-## Animal is-a object (yea, sort of confusing) look at the extra creditclass Animal(object): # 定义动物 pass## ? is-aclass Dog(Animal): # 定义狗,隶属于动物 def...原创 2018-10-20 10:19:29 · 563 阅读 · 0 评论 -
笨方法学Python 习题24
print("Let's practice everything.")print('You\'d need to know \'about escapes with \\ that do \n newline and \t tabs.')poem = """\t The lovely worldwith logic so firmly plantedcannot discern \n...原创 2018-09-26 22:40:26 · 148 阅读 · 0 评论 -
笨方法学Python 习题39
字典、可爱的字典# create a mapping of state to abbreviationstates = { 'Oregon': 'OR', 'Florida': 'FL', 'California': 'CA', 'New York': 'NY', 'Michigan': 'MI'}# create a basic set of...原创 2018-10-02 13:40:53 · 242 阅读 · 0 评论 -
笨方法学Python 习题19
def cheese_and_crackers(cheese_count, boxes_of_crackers): print(&quot;You have {0} cheeses!&quot;.format(cheese_count)) print(&quot;You have {0} boxes of crackers!&quot;.format(boxes_of_crackers)) print(&quot;Man原创 2018-09-23 23:12:47 · 167 阅读 · 0 评论 -
笨方法学Python 习题16
笨方法学Python 习题16from sys import argvscript, filename = argvprint(&amp;amp;quot;We're going to erease {0}.&amp;amp;quot;.format(filename))print(&amp;amp;quot;If you don't want that, hit CTRL-C (^C).&amp;amp;quot;)print(原创 2018-09-21 14:34:41 · 157 阅读 · 0 评论 -
笨方法学Python 习题1
‘’ 'javascriptprint(“hello world!”)原创 2018-09-21 14:40:06 · 152 阅读 · 0 评论 -
笨方法学Python 习题15
from sys import argv #引入argvscript, filename = argvtxt = open(filename) #打开文本文件print(&quot;Here's your file %r:&quot; % filename)print(txt.read())print(&quot;Type the filename again:&quot;)file_again = input('&a原创 2018-09-22 08:40:49 · 212 阅读 · 0 评论 -
Python 文本的处理
先open, 并赋值给一个中间变量(当然这个中间变量可以省略).对中间变量进行操作,操作的结果对原来文本依然有效.举例: 将 from_file. txt 复制到 to_file. txt 中借助中间变量from sys import argvscript, from_file, to_file = argvin_file = open(from_file) # 打开 from...原创 2018-09-22 20:43:06 · 364 阅读 · 0 评论 -
笨方法学Python 习题 20
from sys import argv # 依然调用 argvscript, file_name = argv # 解包变量 argvdef print_all(f): # 定义函数。 print(f.read()) # 函数功能:打印文本内容。def rewind(f): # 定义函数。 f.seek(0) # 函数功能:回到文本的初始位置def print_...原创 2018-09-24 15:39:41 · 472 阅读 · 0 评论 -
笨方法学Python 习题21
函数可以返回某些变量def add(a,b): print("Adding {0} + {1}".format(a,b)) return(a+b)def subtract(a,b): print("SUBTRACT {0} - {1}".format(a,b)) return(a-b)def multiply(a,b): print("MULTIP...原创 2018-09-24 16:35:58 · 302 阅读 · 0 评论 -
笨方法学Python 习题38
ten_things = "Apples Oranges Crows Telephone Light Sugar"print("Wait there's not 10 things in that list, let's fix that.")stuff = ten_things.split(' ') # 讲 ten_things 的元素分开, 并将分开之后的元素创建成 数组more_s...原创 2018-09-30 23:57:26 · 198 阅读 · 0 评论 -
笨方法学Python 习题37
使用Python 获取帮助查看关键字在终端运行 help 命令help("keywords")help("open")help("def")del 的用法# 查看关键字# 在终端运行 help 命令# help("keywords")# help("open")# help("def")# 新命令 delA = ['a','b','c','d','e','f'原创 2018-10-01 17:23:19 · 121 阅读 · 0 评论 -
Python中 format 的功法
format 的用法print('{名字} 今天 {动作}.'.format(名字 = '王同学',动作 = '拍视频')) # 利用关键字grade = {'名字': '王同学', '分数': '59'} # 字典print('{名字} 电工考了 {分数}.'.format(**grade)) # 利用关键字 + 字典print('{1} 今天 {0}'.format('拍视频','王同...原创 2018-10-01 22:24:59 · 188 阅读 · 0 评论 -
笨方法学Python 习题18
命名、变量、代码和函数# this one is like your script with argvdef print_two(*argv): arg1,arg2 = argv print("arg1: {0}; arg2: {1}".format(arg1,arg2)) # arg1,arg2 都是局部变量;不是全局变量# 单独定义的变量才是全局变量# OK, this *a...原创 2018-09-23 22:59:03 · 170 阅读 · 0 评论