![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python基础知识
DMU_lzq1996
这个作者很懒,什么都没留下…
展开
-
转义字符与input
#转义字符table_cat = "\tI'm tabbed in."persion_cat = "I'm split\non a line."backslash_cat = "I'm\\a\\cat."fat_cat = """I'll do a list:\t*Cat food\t*Fishies\t*Cat原创 2018-09-19 19:01:02 · 240 阅读 · 0 评论 -
类定义
class Song(object): def __init__(self,lyrics): self.lyrics = lyrics def sing_me_a_song(self): for line in self.lyrics: print(line) happy_baby...原创 2018-09-27 16:53:06 · 222 阅读 · 0 评论 -
字典{}
states = { 'Oregon':'OR', 'Florida':'FL', 'California':'CA', 'New York':'NY', 'Michigan':'MI'}cities = { 'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}citie...原创 2018-09-26 19:31:35 · 131 阅读 · 0 评论 -
关键字;数据类型;转义字符;格式化字符串;操作符
关键字(Keywords)and:和del:删除变量from:导入相应模块not:否while:while循环as:使用标准库中的模块,如import numy as npelif:if循环分支global:全局变量声明or:或with:用来异常处理assert:断言,声明其布尔值必须为真的判定,如果发生异常则说明表达式为假,可以用来判断表达式的真假else:if循环分支...原创 2018-09-26 15:40:36 · 447 阅读 · 0 评论 -
逻辑循环组合小游戏
animals = ['bear','python','peacock','kangaroo','whale','platypus']animals[0]'bear'from sys import exitdef gold_room(): print("This room is full of gold. How much do you take?") ne...原创 2018-09-25 20:04:48 · 190 阅读 · 0 评论 -
创建函数
def print_two(*args): arg1,arg2 = args print("arg1:%r,arg2:%r"%(arg1,arg2)) def print_two_again(arg1,arg2): print("arg1:%r,arg2:%r"%(arg1,arg2)) def print_one(arg1): prin原创 2018-09-22 12:03:59 · 149 阅读 · 0 评论 -
if-else语句;while和for循环;列表【】操作
print(3!=4 and not ("testing"!="test" or "python"=="python")) Falsepeople = 20cats = 30dogs = 15if people<cats: print("Too many cats!The word原创 2018-09-24 16:23:59 · 248 阅读 · 0 评论 -
计算函数;字符串函数
def add(a,b): print("ADDING%d+%d\n"%(a,b)) return a+bdef subtract(a,b): print("SUBSTRACT%d-%d\n"%(a,b)) return a-bdef multiply(a,b): print("MULTIPLY%d*%d\n"%(a,b))原创 2018-09-23 16:23:18 · 264 阅读 · 0 评论 -
argv参数导出txt文件
from sys import argvfrom os.path import existsscript,from_file,to_file = argvprint("Copying from %s to %s"%(from_file,to_file))indata = open(from_file).read()print("The input file is %d type ...原创 2018-09-22 12:07:10 · 273 阅读 · 0 评论 -
利用argv写入txt文件
from sys import argvscript,input_file = argvdef print_all(f): print(f.read()) def rewind(f): f.seek(0) def print_a_line(line_count,f): print(line_count,f.readline()) cur...原创 2018-09-22 12:05:02 · 548 阅读 · 0 评论 -
argv参数打开txt文件
from sys import argvscript,filename = argvprint("We're going to erase %r."%filename)print("If you didn't want that,hit CTRL-C")print("If you do want that,hit R原创 2018-09-22 12:03:26 · 594 阅读 · 0 评论 -
变量,字符串,数值
#笨办法学Python习题1-9#print输出print("hello world")print("hello python")print("i like typing this")print("this is fun")hello worldhello pytho原创 2018-09-21 10:55:05 · 228 阅读 · 0 评论 -
txt文件作为参数
from sys import argvscript,filename = argvtxt = open(filename)print("Here's your file %r:"%filename)print(txt.read())print("Type the filename again:")file_again = input(">")原创 2018-09-19 19:09:07 · 588 阅读 · 0 评论 -
利用argv传参
from sys import argvscript,user_name = argvprompt = '>'print("Hi%s,I'm the %s script."%(user_name,script))print("I'd like to ask you a few question.")print("Do you like me %s?"%原创 2018-09-19 19:08:36 · 600 阅读 · 0 评论 -
argv参数变量
#参数,解包,变量from sys import argvscript,first,second,third = argv #argv参数变量,包含了传递给python的所有参数print("The script is called:",script)print("The first variable is:",first)print("The second variable is:&quo原创 2018-09-19 19:07:19 · 135 阅读 · 0 评论 -
python内置模块
from collections import namedtuplePoint = namedtuple('Point',['x','y'])p = Point(1,2)pPoint(x=1, y=2)from collections import dequeq = deque(['a','b','c'])q.append('x')q.appendleft('y')qde...原创 2018-12-05 20:46:41 · 185 阅读 · 0 评论