'as'操作符的作用是什么?(What does the 'as' operator do? [duplicate])
这个问题在这里已经有了答案:
`as`命令在Python 3.x中做了什么? 2个答案 “with”语句是为什么设计的? 10个答案我正在从Zed Shaw的Learn Python the Hard Way学习Python的基础知识。 我目前正在阅读第36章(符号评论),并遇到了“as”操作符。 我需要在Python中搜索它的用法。 我知道这个问题很广泛,但是我没有在python.docs上找到任何东西,或者说SO。 这个操作员做什么?
This question already has an answer here:
What does the `as` command do in Python 3.x? 2 answers What is the python “with” statement designed for? 10 answersI am learning the basics of Python from Zed Shaw's Learn Python the Hard Way. I am currently at chapter 36 (Symbol review), and came across the 'as' operator. I need to search for it's uses in Python. I know this question is broad, but I didn't found anything as far on python.docs, or SO. What does this operator do?
最满意答案
它用于在导入模块或使用with子句时创建别名:
import pandas as pd df = pd.DataFrame() ##### with open(file_name, 'r') as my_file: my_file.readlines()It is used to create an alias when importing modules or when using the with clause:
import pandas as pd df = pd.DataFrame() ##### with open(file_name, 'r') as my_file: my_file.readlines()更多推荐
发布评论