美文网首页
python __all__ yield 字符串一些操作

python __all__ yield 字符串一些操作

作者: 明明就_c565 | 来源:发表于2020-09-18 14:25 被阅读0次

1,__all__是一个字符串list,用来定义模块中对于from XXX import *时要对外导出的符号,即要暴露的借口,但它只对import *起作用,对from XXX import XXX不起作用。

test.py

__all__=['x','y','test']

x=2

y=3

z=4

def test():

    print('test')

使用 for test import *  x y test直接可用 但是要想使用z 必须为from test import z

2,python字符串对齐

‘hello’.rjust(20,'*')

定义字符串长度为20,'hello'字符对齐到右边,前面填充‘*’

ljust()和rjust()类似,为对齐到左边

center()类似,对齐中间

3,python字符串去掉空格

lstrip() 去掉左边的空格或其他字符  lstrip(‘*’)

rstrip() 去掉右边的空格或其他字符  lstrip(‘#’)

4,python yield 使用 yield用于迭代器

带yield的函数是一个生成器

举例:

def test():

    for i in range(5):

        yield i*100 + i

for i in test():

    print(i)

输出 101 202 303 404

相关文章

  • python __all__ yield 字符串一些操作

    1,__all__是一个字符串list,用来定义模块中对于from XXX import *时要对外导出的符号,即...

  • python中的yield

    第一次看到yield是在python学习手册上,在python表达式操作符这一节:操作符 :yield x 描述...

  • python进阶-特殊变量和属性

    本文主要记录了python中一些特殊变量或者属性的说明,比如__all__等。 __all__ 先看代码,假设有两...

  • Python常用语法二

    Python 字符串操作和文件操作以及其它Python能力补充 Python字符串操作 in和not in: 'x...

  • python yield和yield from用法总结

    python yield和yield from用法总结 yield 作用: 注: generator的next()...

  • python: yield

    python: yield

  • [转载]python之__all__

    [转载]使用__all__暴露接口 在Python中我们可以使用__all__暴露出模块级别的接口: 这样在其他模...

  • Python yield关键字

    Python中yield关键字解释 这篇文章关于python的yield关键字。并且文章中会解释什么是yield,...

  • 阅读bk_monitor

    Python标准模块--functools __all__的作用 https://www.cnblogs.com/...

  • Python初学(十)

    这章学习下字符串的操作。 字符串的操作 字符串操作符: 针对字符串,Python语言提供了几个基本操作符 字符串处...

网友评论

      本文标题:python __all__ yield 字符串一些操作

      本文链接:https://www.haomeiwen.com/subject/qydcsktx.html