Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the 'as' operator do? [duplicate]

I 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?

like image 981
Litwos Avatar asked Dec 24 '22 16:12

Litwos


1 Answers

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()
like image 138
DeepSpace Avatar answered Jan 06 '23 07:01

DeepSpace