使用python处理工作中遇到的一些知识点汇总(二)

今天是2020年2月15号,肺炎疫情还在延续,为了自己,为了家人,请保护好自己!祈祷这场没有硝烟的战争早日结束!


使用python处理工作中遇到的一些知识点汇总(二)

中国加油


1. 工作中有时会在cmd中启动一些程序,比如:
#启动 chrome吧 
> C:Program Files (x86)GoogleChromeApplicationchrome.exe
#这里会显示报错的,原因是中间出现了空格,解决办法是 加上引号
> "C:Program Files (x86)GoogleChromeApplicationchrome.exe" 再执行就不会报错了
2.数据格式化-format()
参数: formate(value,format_spec='', /)
#格式化float类型的数据,如12.123
> format(12.123,'10.8f') # 10.8f 意思为: 10 为代表长度,.8代表小数点的位数,f代表浮点数的类型,d表示整数 %表示用百分号表示,s代表字符串,默认为右对齐,使用< 小于号则表示左对齐
#左对齐
> format(12.123,'<10.8f')
#左对齐,位数不够的用户指定值填充,用0来填充
> format(12.123,'0<10.8f') #12.12300000
#右对齐前面补零,有时会用到
>format(12.123,'0>10.5f') #'0012.12300'
#带符号
>format(12.123,'+.5f') #'+12.12300'
>format(-1,'+.5f') #'-1.00000' 这个 有的时候会用上
#千分位表示法(金额表示法)
>format(10000,',') #10,000  
#百分号表示
>format(.12,'.2%') #12.00%
#也可以这样表示
> '{.2f}'.format(3.1415) #3.14
​
3.查看python内置函数和内置对象--dir(builtins)
#函数 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', 'WindowsError', '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', 'pmod', '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']


使用python处理工作中遇到的一些知识点汇总(二)

众志成城


4. 有的函数不知道怎么用,可以用这个函数 help()
> help(exec)  #
Help on built-in function exec in module builtins:
​
exec(source, globals=None, locals=None, /)
    Execute the given source in the context of globals and locals.
    
    The source may be a string representing one or more Python statements
    or a code object as returned by compile().
    The globals must be a dictionary and locals can be any mapping,
    defaulting to the current globals and locals.
    If only globals is given, locals defaults to it.
5.python中的成员运算符与身份运算符
在python中任何一个对象都是满足身份(identity),类型(type),值(value)
#成员运算符 in
>>> list1=[1,2,3]
>>> 2 in list1
True
#身份运算符 is
>>> num=1
>>> num2=1
>>> num is num2
True
# not in  不在
>>> 2 not in list1
False
# is not
>>> num  is not num2
False
# 在python中任何对象都可以通过bool()函数进行布尔值判断,结论如下: 0,None,及所有空的序列与集合布尔值全部为False 其他为True
6. python中常用的循环
# for ... in ...
> for i in range(1,10): # 99乘法表,注意range()函数的,并不包括最后一个数
    for j in range(1,10):
        print('{} * {} = {}'.format(i,j,ixj))
# while循环
> while True:
    print('这是一个死循环')


展开阅读全文

页面更新:2024-03-06

标签:会报   千分   百分号   众志成城   小数点   下划线   引号   知识点   整数   函数   对象   成员   身份   类型   代表   数据   工作   科技

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top