Curriculum
Now that Python and PyCharm are installed on your computer, it is time to write and execute your first Python program using PyCharm.
In this section, you will learn:
print() functionBy the end of this lesson, you should have successfully written and executed your first Python program using PyCharm.
You should also have a clear understanding of what your code does.
While Python provides an interactive shell (called REPL), we will primarily use the PyCharm IDE as our environment for writing and running code. PyCharm comes with an integrated Python console if you still want to run one-off commands, but let’s start with the basics of managing an entire Python file in a project.
PyCharm will create a new project folder with default settings.

A Python script is an ordinary file containing Python code, and having the file extension .py.
You will create this file now in PyCharm. Follow the steps below.
hello.py.Once created, PyCharm will open the file in the editor window. Add the following code:
# This is my first Python program
print("Hello, World!")
Output:
Hello, World!
Congratulations! You have successfully written and executed your first Python program in PyCharm. Next, lets explore the print() statement as you would be using it very frequently. It is essentially a function since it can be called and passed a parameter in the brackets.
print() FunctionIn Python, the print() function is one of the most commonly used tools for communicating information back to you (the developer) and others who might read your program’s output.
Anything you pass to print() – such as text, variables, or expressions – will be displayed in the console. In PyCharm, that is typically the Run or Console tab.
print()?Apart from being a clear and short instruction, the print() statement provides the following benefits.
print() is a quick way to see the results of computations or the values of variables, making it invaluable for testing and debugging.print() statements to trace the flow of execution, see intermediate values, and locate potential issues in your code.Below are examples of basic uses of the print() statement.
# Printing a string
print("Welcome to Python!")
Output:
Welcome to Python!
# Printing numbers directly
print(5)
# Printing the result of an expression
print(10 + 20)
Output:
5
30
print("My name is", "Alice", "and I am", 25, "years old.")
Output:
My name is Alice and I am 25 years old.
print() Featuressep parameter (for example, print("A", "B", "C", sep="-") will output A-B-C).print() ends with a newline. You can change this using the end parameter (for example, print("Hello", end="") will continue printing on the same line).print() function is essential for both displaying information to the user and aiding in debugging.Comments are lines or blocks of text in your code that Python completely ignores during execution. Despite being ignored by the interpreter, comments are crucial for making your code understandable to you and others – both now and in the future.
#)You can insert a single-line comment by starting the line (or the end of a line) with the hash symbol (#).
It is often good practice to leave a space after the # for better readability.
# This is a comment
print("Hello, World!") # This prints a message
######### Section 1 #########).""" """ or ''' ''')Multi-line comments allow you to create blocks of descriptive text without prefixing each line with #. They’re handy when you need to add explanations or instructions that span multiple lines.
"""
This is a multi-line comment.
It is useful for adding long explanations
or describing complex logic.
"""
print("This is a Python program.")
""" or ''').#). This makes your code more readable and professional.By thoughtfully incorporating single-line and multi-line comments, your programs will remain clear, maintainable, and easy to navigate – even as they grow more complex.
Variables are a fundamental concept in any programming language, including Python.
They act as containers that hold information which can change over time or remain constant throughout the program, depending on how they are used. Variables make your code flexible, allowing you to store, manipulate, and reference data as your program runs.
age is more descriptive than using a raw number.name = "Alice"
age = 25
print("Hello, my name is", name, "and I am", age, "years old.")
name and age are variables that store a string ("Alice") and an integer (25), respectively.name and age inside the print() function.Output:
Hello, my name is Alice and I am 25 years old.
name = input("Enter your name: ")
print("Hello,", name, "welcome to Python programming!")
input() prompts the user for text, storing whatever is typed into the variable name.print() function then uses the value in name to display a personalized greeting.When you Run this script in PyCharm, the console will prompt for your name, then print a greeting. This simple example demonstrates how variables enable your program to respond dynamically to user input.
Key Takeaways:
user_name, total_cost, is_logged_in) to make your code self-explanatory.Programming errors happen to everyone, especially when you are starting out.
Knowing how to spot and fix them quickly is an essential skill for any developer. In Python, one of the most common types of errors is the syntax error, which indicates that you have written code in a way that Python does not understand.
( has a matching ), and similarly for [ ] or { }.print("Hello, World!) # Missing closing quote
When you run this, PyCharm (or Python in general) will return an error:
SyntaxError: EOL while scanning string literal
What Does This Mean?
EOL stands for end of line. Python reached the end of the line (or file) and was still looking for the matching quote." " or ' ').print("Hello, World!") # Corrected version with matching quotes
Tip: If multiple errors appear, fix them one at a time. For each fix, re-run your code to confirm that you have resolved the specific error. Then move to the next one.
Other common errors that occur apart from syntax errors are:
Debugging means identifying why the error is happening and applying a suitable fix. As you gain more experience, you will become quicker at spotting these pitfalls and preventing them from occurring.
In this lesson, we have covered the following:
.py) and execute it directly within PyCharm.print() function displays text and variables in the PyCharm console.#) help document your code for clarity.input().In the exercise, you will have the opportunity to practice writing your own Python scripts using the knowledge that you have gained so far.
We noticed you're visiting from United Kingdom (UK). We've updated our prices to Pound sterling for your shopping convenience. Use United States (US) dollar instead. Dismiss
Not a member yet? Register now
Are you a member? Login now