python学习笔记,以下是代码
'''''''################## 输出函数print() ##################'''
'''--------------------输出数字、字符串、表达式--------------------'''
# print(520)
# print('helloworld')
# print(3+1)
# #不进行换行输出
# print('hello','world')
'''################## 转义字符 ##################'''
#\t=tab键(\t是根据制表位变化,不一定代表空四格)
# print('hello\tworld')
# print('helloooo\tworld')
# print('hello\rworld') #\r回车符,world把hello给覆盖掉
# print('hello\bworld') #\b退一个格
#\转义字符,以下第一个只输出一个\,第二个才是正确的网址输出
# print('http:\\www.a.com')
# print('http:\\\\www.a.com')
#原字符,不希望转义字符起作用r/R
# print(r'hello\nworld') ###注意!最后一个字符不能是\
'''################## 浮点数运算不精确的解决方案 ##################'''
# n1 = 1.1
# n2 = 2.2
# print(n1+n2) #运算出来存在问题
# from decimal import Decimal
# print(Decimal('1.1')+Decimal('2.2'))
# str1 = '人生苦短,我用python' #一行不能换行
# print(str1,type(str1))
# str2 = "人生苦短,我用python"
# print(str2,type(str2))
# str3 = '''人生苦短,
# 我用python'''
# print(str3,type(str3))
# str4 = """人生苦短,
# 我用python""" #可以换行
# print(str4,type(str4))
'''################## 字符转换 ##################'''
'''--------------------int() float() str()--------------------'''
# s = '182.35'
# print(int(s),type(int(s))) #将字符串转换成int,必须是整数+数字串
'''################## 输入函数 ##################'''
# present = input("你的愿望是什么?\n")
# print(present)
'''--------------------input实现两数相加--------------------'''
'''input输入结果是str类型'''
# a = input("输入第一个数:")
# b = input("输入第二个数:")
# print(a+b,type(a),type(b)) #输入10 20,输出并不是30,而是1020,因为a b的类型是str
# b = int(input("输入第二个数:")) #将输入转换成int
'''################## 运算符 ##################'''
'''--------------------算数运算符--------------------'''
# print(5/2) #除法运算,结果为2.5
# print(5//2) #整除运算,结果为2
# print(2**2) #指数运算
'''--------------------赋值运算符--------------------'''
#a,b,c = 10,20,30 #10→a,20→b,30→c,等号左右两边个数相同
#交换两个值
# a,b = 10,20
# a,b = b,a
'''--------------------比较运算符--------------------'''
'''一个变量包括 标识:id,值:value,类型:type'''
# a,b = 10,20
# print("a>b吗?",a>b) #比较运算符的结果是bool值
# print("a==b吗?",a==b) # ==比较的是两个变量的值value,而不是标识符id类型
'''is 是判断两个变量的标识id是否相等'''
# print(a is b,type(a),type(b))
# lst1 = [11,22,33,44]
# lst2 = [11,22,33,44]
# print(lst1 == lst2)
# print(lst1 is lst2) #False,两个列表不能用同一个id,但是两个变量可以
'''--------------------布尔运算符:and,or,not,in,not in--------------------'''
# s = "helloworld"
# print('w' in s)
# print('a' not in s)
'''--------------------位运算符:& | << >>--------------------'''
'''左移高位溢出舍弃,低位补0,右移高位补0,地位溢出'''
# print(4<<1) #4左移1位
# print(4 & 8)
'''################## 程序的组织结构 ##################'''
'''--------------------对象的bool值--------------------'''
# print(bool(0)) #False
# print(bool(0.0)) #False
# print(bool(None)) #False
# print(bool('')) #False
# print(bool([])) #False空列表
# print(bool(list())) #False空列表
# print(bool(())) #False空元组
# print(bool(tuple())) #False空元组
# print(bool({})) #False空字典
# print(bool(dict())) #False空字典
# print(bool(set())) #False空集合
'''--------------------选择结构--------------------'''
# money = 1000
# s = int(input("请输入取款金额:"))
# if money>=s:
# money = money-s
# print("取款成功,余额为:",money) #不需要用%d / %f
# else:
# print("存款不足以取出",s,"元钱")
'''可以写作 90<=score<=100'''
# score = int(input("请输入你的成绩:"))
# if score >=90 and score<=100:
# print("A级")
# elif score >=60 and score<=90:
# print("B级")
# else:
# print("C级")
'''--------------------条件表达式--------------------'''
# a = int(input("请输入第一个数:"))
# b = int(input("请输入第二个数:"))
# '''一般写作如下:
# if a>=b:
# print(a,"大于等于",b)
# else:
# print(a,"小于",b)'''
# print( (a,"大于等于",b) if a>=b else (a,"小于",b) )
# print( str(a)+"大于等于"+str(b) if a>=b else str(a)+"小于"+str(b) )
'''--------------------pass语句--------------------'''
#什么都不做,只是一个占位符,用于需要写语句的地方
# answer = input("你是会员吗?y/n")
# if answer == 'y':
# pass
# else:
# pass
'''--------------------range函数的创建方式--------------------'''
#只有一个参数
#range(10) #range(stop),start=0,step=1
#两个参数
# range(5,10) #range(start,stop)
# print(range(5,10)) #结果为range(5,10)
# print(list(range(5,10))) #结果为[5,6,7,8,9]
'''直到9,不会到达10'''
#三个参数
# r=range(5,10,2) #range(start,stop,step)
# print(list(r))
'''以下两个虽然产生的数不同,但是占据的内存空间大小相同'''
# print(range(5,10))
# print(range(5,100))