import sys
import re
# 输出
# print ('helloword')
# print(100+300)
# 输入
# name = str(input('输入名字'))
# print('你的名字是',name)
# 转义字符
# print('I\n','am\t','ok')
# 换行符
# print('''line1
# ... line2
# ... line3''')
# and,or
# a=1
# b=2
# c=2
# if a==b or a==c:
# print('true')
# if a==b or b==c:
# print('false')
# 输出格式化字符串,输出变量和常量和字符串混合的内容
# print('Hello, %s' % 'world')
# %s格式化把任何数据类型转化成字符串
# print('age:%s.gender:%s'%(25,True))
# print('age:%s.gender:%s %%'%(25,True))#当%是普通字符时
# 输出
# print ('helloword')
# print(100+300)
# 输入
# name = str(input('输入名字'))
# print('你的名字是',name)
# 转义字符
# print('I\n','am\t','ok')
# 换行符
# print('''line1
# ... line2
# ... line3''')
# and,or
# a=1
# b=2
# c=2
# if a==b or a==c:
# print('true')
# if a==b or b==c:
# print('false')
# 输出格式化字符串,输出变量和常量和字符串混合的内容
# print('Hello, %s' % 'world')
# %s格式化把任何数据类型转化成字符串
# print('age:%s.gender:%s'%(25,True))
# print('age:%s.gender:%s %%'%(25,True))#当%是普通字符时
#打印
# n = 123
# f = 456.789
# s1 = 'Hello, world'
# s2 = 'Hello, \'Adam\''
# s3 = r'Hello, "Bart"'
# s4 = r'''Hello,Lisa!'''
# print(n)
# print(f)
# print(s1)
# print(s2)
# print(s3)
# print(s4)
#将字符串转换成ascall码值
# print(ord("a"))
# print(ord("A"))
# print('\u4e2d\u6587')
#打印不同编码
# print('ABC'.encode('ascii'))
# print('中文'.encode('utf-8'))
#list
# mate=['one','two','three','four','five','six','seven']
# print(mate[0])
# print(mate[-1])
# mate.append('eait')#添加
# mate.insert(5,'6')#插入
# print(mate)
# mate.pop(3)
# print('删除后')#删除
# print(mate)
# mate[2]='replace'
# print(mate)
# print('list中还是list')
# listtext=[1,2,3,4,5,['a','b','c'],5,6]
# print(len(listtext))
# print(listtext)
#元组tuple,代码里面的数值不可以改变
# mate=('one','tow','three')
# print(mate)
# print(mate[1])
# t=()#空tuple
# y=(1,)#定义一个只有一个元素的tuple
# print(y)
#可以变的tuple
# u = ('a', 'b', ['A', 'B'])
# u[2][0]='s'
# u[2][1]='d'
# print(u)
#for循环
# names=[1,2,3,4,5]
# for name in names:
# print(name)
# sum=0
# for x in [1,2,3,4,5,6,7,8,9]:
# sum=sum+x
# print(sum)
# sum=0
# for x in range(101):
# sum=x+sum
# print(sum)
# while循环
# sum = 0
# n = 99
# while n > 0:
# sum = sum+n
# n = n-2
# print(sum)
#dict字典,就是键值对
# name={'mic':1,'wula':0}
# names={'lili':'乌鸡国','lala':'ing大'}
# print(name['mic'])
# print(names['lili'])
# name['mic']=12#可以赋值
# print(name['mic'])
# print(name)
# print('jjj' in name)#判断是不是有这个字段
# print(name.get('lilis','值不存在'))
# name.pop('wula')#删除掉一个键值对
# print(name)
#特殊字典set,不存储值,只有键
# s =set([1,2,3])
# d=set([1,2,3,4,5,6,2,3,44])
# print(s)
# print(d,'自动不显示重复值')
# s.remove(1)#删除数值
# print(s)
# #打印交集并集很好用
# print(s&d)
# print(s|d)
# 内置函数
# print(abs(-10))
# print(max(1,2,4,5,6,7,23))
# print(min(1,2,4,5,6,7,23))
#数据类型转换
# print(int('223'))
# print(hex(120))#16进制打印
#自定义函数
#终端内调用才有用
# def abs(x):
# if x>=0:
# return x
# else:
# return-x
# def power(x,n):#求平方
# s=1
# while n>0:
# n=n-1
# s=s*x
# return s
# def stuinfo(name,gender,age=6,city='南昌'):#默认值
# print('名字:',name)
# print('年龄',age)
# print('居住地',city)
# print('gender',gender)
# def sum(number):#可变参数参数用一个列表装进去
# s=0
# for n in number:
# s=s+n*n
# return(s)
# def sums(*number):#可变参数
# s=0
# for n in number:
# s=s+n*n
# return(s)
#递归,函数内部调用自身就是递归,计算阶乘
# def fact(n):
# if n==1:
# return 1
# return n*fact(n-1)
# 打印数列1到99
# num=[]
# a=1
# while a<100:
# num.append(a)
# a=a+2
# print(num)
#打印99乘法表
# for i in range(1,10):
# for j in range(1,10):
# print(i,'*',j,'=',i*j)
#切片
# l=[1,2,3,4,5,6,7,8,9,10]
# print(l[0:2])#取前两个值
# print(l[-2:-1])#取倒数第二个开始一个值
# print(l[::3])#每三个取一个
# 列表生成式
# print(list(range(1,11)))
# 迭代器
#生成1的平方,2的平方....
# list=[1,2,3,4]
# it = iter(list)
# for x in it:
# print(x*x)
# list = [1,2,3,4]
# it=iter(list) #创建迭代对象
# print(next(it)) #输出迭代的下一个元素
# print(next(it))
# 生成器
# L = [x * x for x in range(10)]#生成一个对象
# print(L)#调用
#高阶函数
# def add(x,y,f):#定义函数调用
# print(f(x) + f(y))
# add(-5,6,abs)
#map reduce
# def f(x):
# return(x*x)#定义一个平方函数
# r=map(f,[1,2,3,4,5,6,7,8,9])#使用map函数方法对这个数列进行调用
# print(list(r))
# def cuboid(x,y,h):
# print('长方体体积为',x*y*h)
# print('长方体表面积是',(x*y+x*h+y*h)*2)
# i=int(input('输入宽'))
# j=int(input('输入长'))
# k=int(input('输入高'))
# cuboid(i,j,k)
#文件读写练写
#f = open('public/txt/demo.txt')
#while True:
# lines=f.readlines()
# if not lines:
# break
# pass
f.close()
python练手题目
于 2021-12-16 14:08:23 首次发布