杂乱(具体看摘要)

Spyder两种注释方法

CTRL+4 块注释

CTRL+5 取消块注释

CTRL+1 行注释与取消

输入

name=input("qing>\n")
print("您好"+name)

控制结构

if判断

score = float (input())
if score>=90:
    print('恭喜')
elif score>=80 and score<90 :
    pass
    print("fdg")
else :
       print("4544")

 

while循环

i=1;
 while i<=9 :
     j=1
     while j<=i :
         print(i," * ",j," = ",i*j,"\t",end="")
         j+=1
     print("")
     i+=1

  

for循环

name="kdnnfnafn"
for x in name:
    print("-----------")
    print(x)
    if x=='f':
        break
    elif x=='n':
    else :

 

功能模块

时间模块

import time,datetime  
print(time.time())
print(time.strftime("%Y-%m-%d %X"))
print(time.strftime("%Y-%m-%d %x"))
print(time.strftime("%Y-%m-%d %M %M %S"))
​
print(time.localtime())
print(datetime.datetime.now())
print(datetime.datetime.now()+datetime.timedelta(days=3))
print(datetime.datetime.now()+datetime.timedelta(days=-3))

 

运行截图

random模块

import random
random.random()                 #大于0且小于1之间的小数
random.randint(1,3)             #大于等于1且小于等于3的整数
random.randrange(1,3)           #大于等于1且小于3的整数
random.choice([1,'23',[4,5]])   #1或23或[4,5]选项
def v_code(): #并验证码用王循环数字和字母相平的验证码
    res = ""   #验证码是字符串,首先有个初始值
    for i in range(5) : #进表示5位数的随机验证码
        num = random.randint(0,9) #取到数字
        alf = chr (random.randint (65, 90)) # 返回对应的asscii码
        s = str(random.choice([num,alf]))  #做转换
        res +=s           
    return res        #返回字符串拼接的结果
print(v_code())   #调用函数

os模块

import os                     #os文件模块
print(os.getcwd())          #获取当前工作目录
os.chdir("..")              #获取当前工作目录的父目录字符串名 print(os.getcwd())
os.makedirs("dir/dirname")  #生成多个目录
os.removedirs("dir/dirname")#删除目录

Psutil模块

import psutil   #监控模块
print(psutil.cpu_times())
print(psutil.cpu_times().user)

python包和模块

#from 模块名 import 函数名1 函数名2 ...

函数

缺省参数

只能放在后面定义

def test(a,b,c=112)
def test(a,b=12,c=1)
def test(a,b,*args) #变量名无所谓,主要*+变量名
#test(12,12,15,1,2,3)   #a=12 b=12 args=(15,1,2,3)为元组形式  def test(a,b,*args,**kwargs) # kwargs以字典形式返回  

 

匿名函数

一次使用,随用随定义

lambda X:X+1

有名函数

可以重复调用

def 函数名():
  

 


   

 

 

posted @ 2020-02-14 14:29  JZCTPP  阅读(149)  评论(0编辑  收藏  举报