Python教程

Python 6.21

本文主要是介绍Python 6.21,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

from math import pi as P
from os.path import getsize
from random import choice
from itertools import *
import math

r = 3
print(round(Prr,2))
print(choice('Python'))
print("----------------")

characters = '1234'
for item in combinations(characters,3):
print(item,end = '')
print('\n'+'='*20)
for item in permutations(characters,3):
print(item,end = '')
print("----------------")

print (math.factorial (32))
print (math.isclose (0.4-0.3,0.1))
num = 7
squreRoot = num ** 0.5
print (squreRoot2 == num)
print (math.isclose(squreRoot
2,num))
print("----------------")

X=0b1011
print (X)
print("----------------")

z=1.2+3.4j
print (z.imag)
print("----------------")

x=6
y=-5+2j
print (x+y)
print("----------------")

x=5
y=2
print (x/y,x//y)
print("----------------")

x_list = [1,2,3,5,8,9] #列表
print (x_list[5],x_list[3])
print (len(x_list)) #查看列表长度
print (max (x_list))
print("----------------")

x_tuple = (1,2,3,5,6,8,9,25) #元组
print (x_tuple.index(2)) #查看元素2在元组中时首次出现的位置
print("----------------")

x_set = { 1, 2 , 3 , 4,8} #集合
print (max (x_set)) #查看集合中最大值
print("----------------")

x_dict = {'a':97, 'b':98 ,'c':99} #字典
for key ,value in x_dict.items():
if value == 98:
print (key) #查看字典中98对应的键
print("----------------")

text = '''Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.'''
print (len (text)) #字符串长度
print (text.count('is')) #is出现的次数
print ('beautiful' in text) #是否包含单词beauiful
print ('='*20) #字符串重复
print ('Good' + 'Moring')
print("----------------")

这篇关于Python 6.21的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!