首页  

python3-001 基础语法     所属分类 python 浏览量 432
关键字
import keyword
print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 
'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 
'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 
'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

单行注释
# 单行注释

'''
多行注释line1
多行注释line2
多行注释line3
'''

"""
多行注释line1
多行注释line2
多行注释line3
"""

多行语句 反斜杠(\)
print \
('hello')

数字类型 int, bool, float, complex(复数)
字符串 单引号 和 双引号 使用完全相同
三个单引号 或 双引号 ,多行字符串
str = """hello
python3
"""
str1 = '''hello
python3 2
'''

不转义
str2 =  r"hello \n python3"
print(str2)

字符串 + 连接 , * 重复
print("hello "+"world")
print("hello"*3)


字符串 索引,从左往右以 0 开始,从右往左以 -1 开始
字符串不可变
没有单独的字符类型,一个字符就是长度为 1 的字符串
字符串 截取  [头下标:尾下标:步长]
str="hello"
print(str[0])
print(str[0:3])
print(str[0:-1])
# 倒序  步长-1 
print(str[-1::-1])

空行用于分隔两段不同功能或含义的代码
同一行中使用多条语句,语句之间使用分号(;)分割

print 默认换行 end="\n"
print('hello ', end="")
print('world')

导入整个模块(somemodule)  import somemodule
导入某个模块中的某个函数    from somemodule import somefunction
导入某个模块中的全部函数    from somemodule import *

AttributeError: module 'myutil' has no attribute 'myutil_hello1'
注意 模块  __init__.py  的写法 

myutil
  __init__.py
  myutil001.py


__init__.py
from .myutil001 import *



myutil/myutil001.py def myutil001_hello1(name): print("myutil_hello1 run,hello,"+name) def myutil001_hello2(name): print("myutil_hello2 run,hello,"+name)
使用 myutil 模块 import myutil myutil.myutil001_hello1("tiger") from myutil import myutil001_hello2 myutil001_hello2("cat")

上一篇     下一篇
wireshark 抓包

fate flow 命令行 请求 抓包分析

网络报文分析利器eBPF简介

python3-002 基本数据类型

python3-003 条件和循环

python3-004 迭代器和生成器