Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Categories

Chapter 1.2: Understanding the Python shell and writing your first program

Learning the basics of Python shell and writing the first program

In the previous section, we walked through the process of installing Python and setting up a suitable Integrated Development Environment (IDE). With these tools in place, we are now ready to start coding.

Understanding the Python Shell

The Python shell is an interactive interpreter that allows us to run Python code line by line. It’s an excellent tool for testing out small snippets of code and debugging.

Let’s open the Python shell. If you’re using an IDE like PyCharm or Visual Studio Code, the Python shell (also called the Python console) is usually available within the IDE. If you’ve installed Python directly, you can open the shell by typing python (or python3 on some systems) in your terminal.

In the Python shell, you should see something like this:

Python

The >>> symbol is the Python prompt where we can type Python code.

Let’s try a simple command:

Python

In the above example, we called Python’s built-in print function, which outputs the provided string to the console.

Writing Your First Program

Now that we’ve gotten a taste of the Python shell, let’s write our first Python program.

Python programs are simply text files with the extension .py. You can create a Python file in your chosen IDE or text editor.

Let’s create a file called hello_world.py and write the following code in it:

Python

We’ve written our first Python program! To run it, navigate to the directory containing hello_world.py in your terminal and run the command python hello_world.py (or python3 hello_world.py if needed). The output should be:

Python

Congratulations! You’ve now used the Python shell and written and run your first Python program.

Next Steps

In the following sections, we will discuss variables, data types, and operators. You’ll start to learn how to store and manipulate data in Python, which is the basis of all Python programming.


This is a very basic introduction. As we progress further into Python, we’ll delve into more complex topics and create more elaborate programs.

Leave a Reply

Your email address will not be published. Required fields are marked *