How to call a function from another file in Python

0 votes

Hi Guys,

I have one function in a python file. I want to use this function in a different python file. How can I call a function from another file in python?

Jun 24, 2020 in Python by akhtar
• 38,230 points
4,824 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use the import keyword to call your function. I have attached one example below. You can go through it.

Say you have one python file like this.

$ notepad basic.py
  def fun(x,y):
    z= x+y
    return (z)

Now you can call this function into a different python file like this.

from basic import fun
data=fun(3,3)
print(data)

I hope this will give you some ideas.

answered Jun 24, 2020 by MD
• 95,440 points

Related Questions In Python

0 votes
1 answer

How to create and read from a temporary file in Python?

Hi, there is a very simple solution ...READ MORE

answered Jan 29, 2019 in Python by Nymeria
• 3,560 points
1,753 views
0 votes
0 answers
–1 vote
2 answers
0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,910 points
2,075 views
0 votes
3 answers

Python Selenium best tutorials for beginners

Hope this will help you...Python Tutorial READ MORE

answered Feb 11, 2019 in Python by aldrinjohn
• 140 points
3,441 views
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31, 2020 in Python by MD
• 95,440 points
845 views
0 votes
1 answer

How to crop face from a photo using cv2 in python?

Hi@akhtar, You can do this task using cv2 ...READ MORE

answered Apr 9, 2020 in Python by MD
• 95,440 points
641 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP