Ctrl + d 退出交互模式
print() 打印
>>> print(10+2)
12
input() 输入
>>> a = input("请输入:")
请输入:18
>>> a
'18'
>>> type(a)
<class 'str'> #返回的赋值类型是字符串
type() 查看数据类型
import 导入模块
help(‘keywords’) 查看关键字
>>> help('keywords')
Here is a list of the Python keywords. Enter any keyword to get more help.
False class from or
None continue global pass
True def if raise
and del import return
as elif in try
assert else is while
async except lambda with
await finally nonlocal yield
break
id() 查看内存地址
>>> id(a)
1990988832
dir() 查看方法
dir(__builtins__) #查看所有内置函数
>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
global 引用全局变量
nonlocal 引用局部变量
len() 取长度
>>> a
'18'
>>> len(a)
2
min() 取最小值
>>> a
'18'
>>> min(a)
'1'
max() 取最大值
>>> a
'18'
>>> max(a)
'8'
sorted() 正向排序
>>> a
'524561231651654324'
>>> sorted(a)
['1', '1', '1', '2', '2', '2', '3', '3', '4', '4', '4', '5', '5', '5', '5', '6', '6', '6']
reversed() 反向排序
>>> a = "5187"
>>> for i in reversed(a):
... print(i)
...
7
8
1
5
#所谓的反向排序就是从尾部向首部取值
#要想实现从大到小排序要结合正向排序使用
>>> a = "8467132"
>>> for i in reversed(sorted(a)):
... print(i, end=" ")
...
8 7 6 4 3 2 1