Learn Python programming- Getting started

Getting started with Python

This article covers the most common query – How to start programming in python?


Start python by running the Python interactive prompt.
Just type python (or python3 if you’ve both python 2.x and python 3.x installed) in the command prompt(Windows – Search cmd or command prompt- enter) or terminal(linux – Ctrl+Atl+T) to start the interactive prompt.


Let’s play with some of the most basic command statements in Python:

We won’t break the tradition of introductory program, which is the “Hello World” program.

Do something folks!!! The >>> in the interactive prompt is waiting for you to type something fresh.



The print statement in Python :

Just type the print() statement as it is in the picture and hit enter, you’ll see Hello world! printed in the next line.


Split:

print is a function which does exactly what it says, it prints something, depending upon the data it is provided within the parantheses.
In fact, the interactive Python prompt prints the result of an expression or statement without the use of print() statement and that’s a very brilliant feature, but you should avoid this practice because in Python files, print statement is needed to display something, and instead of getting confused in the future, use print statements in the interactive prompt as well.

Hello World! is a collection of characters and is known as a String in programming languages. You must have noticed that the string is quoted inside single quotes. This is how we represent a String in python. and in most of the programming languages, a string is quoted inside single or double quotes and even back quotes.


You can use the interactive prompt as a calculator. Try solving some elemental computations in the prompt for getting familiar with python and for fun of course.


Using the interactive prompt is fun, but if you want to become a professional python programmer, then you’ll have to do the whole thing in files or python scripts because the commands or statements that you execute in the interactive prompt, get vanished the moment you exit out from the prompt. And also for the ones who are using IDLE, note that IDLE is just a Python’s GUI program so sometimes it hangs while using other heavy Python programs. Therefore, it is recommended to use Python files.


Scripts in Python –

Open text editor and write some some valid Python statements in it and save it as .py file and the best practice is to create a new directory or folder for python files. This is just an example script to learn how to run a python program file, so you don’t have to add a number of lines of code.


How to run python program using terminal or command line :

Now launch python using “python” or “python3” command and mention the python file name to be executed. Don’t forget to mention file path before the file name if the program folder is not the current working directory.


This is how python programs are run using the command line.
You can also use an IDE to run a python program. In fact, you’ll be using an IDE for running,testing and debugging python programs or programs of any other language as they increase the efficiency as a programmer.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

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