Python开始自我学习–第一周–记录–版本号:python3.7–欢迎互相讨论学习
print('----计算X的Y次方-----')
print('2的100次方为:',2**100)
print('3的100次方为:',3**100)
print('----运行系统命令----嘟嘟嘟---')
import sys
print(sys.platform)
print(2**100)
x='spam!'
print(x*8)
#print('----调用并运行指定模块----嘟嘟嘟---')
#import lianshou2 #调用指定语句,命名为英文方可运行
# L=[1,2]
# L = L.append(L)
# print(L)
print('----打印Π数值----嘟嘟嘟---')
import math
print(float(math.pi))
# print('----计算2的100万次方的长度----嘟嘟嘟---')
# print(len(str(2**1000000)))
print('----随便看看----嘟嘟嘟---')
line = 'aaa,bbb,ccccccccc,dd'
print(line.split(','))
#默认参数
salary = '''
小王 10000元
小李 20000元
小徐 15000元
'''
print(salary.splitlines())
#参数设置为True
salary = '''
小王 10000元
小李 20000元
小徐 15000元
'''
print(salary.splitlines(True))
print('----string----嘟嘟嘟---')
s1 = '%s,egg,and %s' %('spam','SPAM!')#通用
print(s1)
s2='{0},egg2, and {1}'.format('spam','SPAM!')#适合2.6、3.0
print(s2)
print('----list列表用法,左含右不含----嘟嘟嘟---')
L = ['123','spam',1.23]
print(L)
print(L[:-1])
print(L[:1])
print(L[:2])
print(L[0:2])
print(L+[1,2,3])
L.append('NI')#不要定义字段
print(L)
L.reverse()#反向打印
print(L)
print('---默认按升序进行打印---')
M =['bb','aa','cc']#整理打印,默认按升序进行打印,常用方法:通过字典的keys()方法收集一个键的列表,使用列表的sort()方法对键列表进行排序,然后使用Python的for循环逐个进行索引显示.
#在最近版本的Python中,通过使用最新的sorted内置函数可以一步完成:for key in
M.sort()
print(M)
print('---矩阵练习,默认0开始---')
M1 = [[1,2,3,],[4,5,6],[7,8,9]]#可以分行比较直观
print(M1[1])#默认0开始
print(M1[1][2])#默认0开始
col2 = [row[1] for row in M1]
print(col2)
col3 = [row[1]+1 for row in M1]
print(col3)
col4= [row[1]for row in M1 if row[1]%2==0]
print('双条件限制位置和数值col4:',col4)
col5= [M1[i][i] for i in [0,1,2]]#001122组合
print('单条件col5为:',col5)
col6= [M1[i][j] for i in [0,1,2]
for j in [0,1]]#012任意组合
print('双条件限制区域col6为:',col6)
print('---矩阵数值之和,next\map用法开始---')
G = (sum(row) for row in M1) #对大列表里面的每一个小列表进行求和,并构造为迭代器
print(next(G))#next() 返回迭代器的下一个项目。
# next() 函数要和生成迭代器的iter() 函数一起使用。
print(next(G))
print(next(G))
print(list(map(sum,M1)))#map(参数1,参数2),将参数1一般为函数名,将参数2中的内容逐个取出作为参数1中的函数的参数,运行结果返回一个迭代器
#list(),将迭代器或可迭代对象的结果取出,放到一个列表中
dict1= {i:sum(M1[i]) for i in range(3)}#矩阵用[],字典用{},集合型用{},3为实际长度
print('标序号创建字典:',dict1)#dict
print('列表型创建:',M1)#L
s1= {sum(M1[i]) for i in range(3)}
print('集合型创建:',s1)
print('---字典学习,+=1,代表数值加1---')
dict2 = {}
dict2['employee number'] = 1
dict2['name'] = 'Bob'
dict2['job'] = 'dev'
dict2['age'] = 40
print('创建字典:',dict2)
print(dict2['name'])
print(dict2['name']+'现年龄为:',dict2['age'],'岁;','距离退休年限:',65-dict2['age'],'年。')
print('---键的排序---')#下次内容更新