跳至主要內容

LincZero大约 1 分钟

Python

学习

模块与导包

Page should have a __init__.py file

import commer.app # 全部导入
commer.app.a_fun() # 调用
# 或:
from app import a_fun # 部分导入
a_fun() # 调用

类型与方法 - 动态强类型

aInt = int(10)  # type=type(10)
aFlo = 10.0
aStr = 'Tom'  # """多行字符串"""
aBool = False
aList = [1, 2, 3]
aMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
aTuples = (1, 2, 3)
aDic = {'1': '3', '2': '2', '3': '1'}
type('变量类型')
id(aInt)

对象与类

class Mammal:
    @staticmethod
    def move():
        print('move')
class Dog(Mammal):  # python特色:不定义直接用
    def __init__(self, name): # 构造函数
        self.name = name
        
dog = Dog('Lucy')

语法

while False:
    if 1 and 1 or not 1:  #'elif, else, x if y else z'
        pass  # (10)if(10>20)else(20)
    for i in range[1, 1, 1]:  # in:Python Special
        pass  # Py没有switch写法'
try:
    pass
except ValueError:
    print('Invalid value')
print(aStr + f' is {aInt}.' )
print('a=%d b=%f' % (a, b))
input('Please:')

函数

def fn1(arg1,arg2):  # 函数定义【位置】:调用之上!支持keyword argument调用
	return arg1+arg2
fn1(1,2) # 调用【位置】:定义之下!
fn2 = lambda arg1,arg2:arg1+arg2
fn2(1,2)

特色

特色

dir(name)

help(name.upper())

pip install

name[0:-1] # 切片

多重判定?

x, y, z = list # 解压缩简写特性

列表解析

盲区

py的占位符

while可以有else

emoji Converter 😃 😦

error

Process finished with exit code 0

Web

Python 3 module index

pypi.org

yelp.com

User Package & Module

import random  # random
form pathlib import Path  # mkfile,glob
pip install opepyxl  # excel
import openxl as xl