Currently set to Index
Currently set to Follow
Skip main navigation

Writing your First Python Program

Assuming that you have successfully installed and set up Python and PyCharm, it’s time to test that everything is working correctly. Let’s use a simple Python function as a test. In your main.py tab, or in a new .py file, type the following line:
Assuming that you have successfully installed and set up Python and PyCharm, it’s time to test that everything is working correctly.
Let’s use a simple Python function as a test. In your main.py tab, or in a new .py file, type the following line:
print('Hello World')
 
This is a traditional first program. Run your program by selecting the green play triangle located on the right-hand side of the top toolbar or press ctrl+F5.
An output pane should appear at the bottom of the window. Under TERMINAL, the output of your code should be:
Hello World
 
Whenever you encounter these code snippet examples, try them for yourself. Copy and paste the code into your code editor. Run the code to see if you obtain the same result. Experiment by changing the code and see how the output changes. You will learn Python a lot faster by playing around with code in this way.
Your head might be spinning with all of this information. However, coding can be a lot of fun. Before we continue on this journey, let’s do some more experimental coding.
 

Practice Coding in Python

 
  1. Open PyCharm, create a new file, and save it as fun_coding.py. In the tabs, we will look at some options. Remember these three basic rules:
    • print() function: the print function will display exactly what you have typed between the parentheses (()).
    • ”” or ‘’: you can choose between using “” or ‘’. Everything between the “” or ‘’ will be returned as a string. You will learn more about this in later topics.
    • Run the code: first save the code and then click on the green triangle in the top right-hand corner of the screen.
  2. See if you can successfully code the following sentences:
    • I like to code in Python.
    • Coding in Python is fun!
    • Python is considered a beginners’ programming language.
  3. Did you find this activity challenging? What insights about Python did you gain while doing this activity?
Congratulations on writing your first Python program – please share this piece if you found it useful.
This article is from the free online

Introduction to Programming with Python

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education