As Python is becoming a popular programming language and everyone wants to get started with Python. But we have seen, most of the developers are confused from where they can start and how to create their first python application. So, this article will demonstrate to you, how you can create your first Python application in Visual Studio 2017 and after creating your first python project, we will see some of the small python examples so that you can get a better picture of how to start writing your program and how to run it.
If you don't have a Python environment ready and you are willing to work with Visual Studio, so don't worry. You can follow my previous article as "Setup and Test Python Environment in Visual Studio 2017". So, let's start and create our first Python project. Visual Studio is the best IDE for .Net Programming language but now it also provides supports for Python. So, we can create a python project and write the code in Visual Studio. While writing the python code in Visual Studio, we can use all Visual Studio features like debugging, intelli-sense etc. We have a different template available for creating the Python project in Visual Studio like you can create a simple project or you can create a single file where you can write your python code and run it. If you are interested to create a web application using python in Visual Studio then we have Django and Flask template, which provides a full flash of the ready-made template. Here we will try to create a simple python project.
First, open your Visual Studio 2017 or later version and click to the File menu and choose New and then Project. It will open "New Project" window from where we can choose different kinds of application templates. But let choose Python from installed section [Left Panel] and from the middle panel select "Python Application" and provide the suitable name and location for this application as showing in the following image and click to OK.
It will take a few seconds to get the project ready as follows. Following image shows the basic structure for Python application, we can extend it as per our requirements. Here you will find "Python Environments" where our application will run. Apart from this, it has a single "FirstPythonDemo.py" file.
The project is ready with one python file and we are ready to write our first program. So, let write the first program in python as follows and run it. Here we are going to print something like a message.
print('This is my first python program')
Now, let run the program in Visual Studio 2017 as generally we do to run the program using F5 and you will get the output as follows.
Great, we are able to run our first python project in Visual Studio. We don't think, you will get an issue if you follow the everything step by step and your python environment setup correctly. Let extend the above program and add some more code to understand the python.
# Example 1
print('This is my first python program')
# Example 2
x =5
y =4
z=x+y
print('The sum of {} and {} is {}'.format(x,y,z))
# Example 3
def sayHello():
print('Hello Programmer')
sayHello()
Here above, we have three basic examples in python as we have already discussed for the first one. It is only printing the text. In the second example, we are declaring two variable as x and y and adding both in the third variable as z and print the output. In the third example, we are creating one method as "sayHello()" and calling it. Let run the program and see the output.
The above output is as expected. First one is printing the text, the second one is giving the sum of 5 and 4 as an output and the third one is a method which again prints some text.
Let's understand something more about python project properties. Sometimes, It is required to work with some other python version, it could be a higher version or lower version. This can be changed from project properties windows. Right click on the project and go to properties, here in the general section, you will find the Interpreter with some of the installed pythons versions as shown in the following image. You can change it if you want. From the General tab, We can also change the Startup File and make some other python file as startup file.
Conclusion
So, today we have learned how to create our first python project in Visual Studio 2017 and run first program and extend it.
I hope this post will help you. Please put your feedback using comment which helps me to improve myself for next post. If you have any doubts please ask your doubts or query in the comment section and If you like this post, please share it with your friends. Thanks
Posted Comments :
srivasskillslash Posted : Last Year
Hi, I appreciate you giving this information; I have read a lot from this article. Visit our website <a href= https://skillslash.com/web-development-course-in-hyderabad/> Web Development Course In Hyderabad </a> These courses are wonderful for Freshers.
srivasskillslash Posted : Last Year
Hi, I have read a lot from this blog thank you for sharing this information. Visit our website <a href= https://skillslash.com/data-science-course-in-ludhiana?utm_source=Off+Page&utm_medium=Srinivasula/> Data Science Course In Ludhiana </a> These courses are wonderful for professionals.
srivasskillslash Posted : Last Year
Hi, I have read a lot from this blog thank you for sharing this information. Visit our website <a href= https://skillslash.com/data-science-course-in-lucknow?utm_source=Off+Page&utm_medium=Srinivasula/> Data Science Course In Lucknow </a> These courses are wonderful for professionals.
srivasskillslash Posted : Last Year
Hi, I have read a lot from this blog thank you for sharing this information. Visit our website <a href= https://skillslash.com/data-science-course-in-aurangabad?utm_source=Off+Page&utm_medium=Srinivasula/> Data Science Course In Aurangabad </a> These courses are wonderful for professionals.
LAXMAN KATTI Posted : Last Year
Hi, I have read a lot from this blog thank you for sharing this information. We provide all the essential topics in Web Development Courses like, Full stack Developer, Python, AI and Machine Learning, Tableau, etc. for more information just log in to our website https://skillslash.com/web-development-course-in-chennai https://skillslash.com/web-development-course-in-pune https://skillslash.com/web-development-course-in-bangalore https://skillslash.com/web-development-course-in-hyderabad
Laxman katti Posted : Last Year
Hi, I have read a lot from this blog thank you for sharing this information. We provide all the essential topics in Data Science Course In Chennai like, Full stack Developer, Python, AI and Machine Learning, Tableau, etc. for more information just log in to our website <ahref=”https://skillslash.com/data-science-course-in-chennai”>Data science course in chennai</a>
khadar Posted : Last Year
Thanks for allowing me to talk about a <a href=https://skillslash.com/data-science-course-in-pune>Data Science Course In Pune </a>. For the Best career in Data science course, I recommend Skillslash is recognized as the <a href=https://skillslash.com/data-science-course-in-pune> Data Science Course Training in Pune </a>. We cover all the essential topics in data science like R, Python, Machine Learning, Deep Learning, Tableau,Full stack etc.
srivasskillslash Posted : Last Year
Hi, I appreciate you giving this information; I have read a lot from this article. Visit our website <a href= https://skillslash.com/data-science-course-in-kolkata?utm_source=Off+Page&utm_medium=Srinivasula/> Data Science Course In Kolkata </a> These courses are wonderful for professionals.