Getting Started With Python Programming

Introduction

 
Python is very simple but magical language, i.e., with a very little code, a big task can be accomplished. In this article, I am going to focus on the basics of Python programming.
 

Python is an interpreted Language

 
When I say interpreted, that means the source code of Python doesn’t get compiled. Instead, it is interpreted directly by the interpreter.
 

Ways to run Python Programs

  1. Interactive Mode
  2. Scripting Mode
Interactive Mode
 
In Interactive mode, Python programs get executed in Python Shell. When you have a small number of statements to execute, the interactive mode is the best option for it. In this mode, execution happens line by line. As we write one statement and hit Enter, that statement will get executed.
 
Python Programming
 
In the above Shell, "hello" is passed as a parameter in print(). As Enter is pressed, print() gets executed and we get hello as output.
 
Scripting Mode
 
In this mode, the series of statements is first stored in a file called source file with .py extension. After writing the code, you can run it by clicking "Run" and then, "Run Module".
 
Python Programming
 
Output
 
Python Programming
 

Values and Types

 
In Python, there is no need to define a datatype of the variable before using it. We directly assign the values to a variable. Through values, the interpreter decides the type of data a variable is holding.
 
Example
 
a=10
 
Here, the data type of variable is not defined. Instead, the interpreter will decide the type of variable through the value provided on the right-hand side of the assignment operator. By looking at the value of a, the interpreter will recognize that a is of type integer. If you want to check the type of data a variable is holding, you can use a factory function called as type().
 

Type()

 
It returns the datatype that a variable is holding.
 
Python Programming
 
Source Code
  1. a= 5  
  2. name="python"  
  3. length=5.2  
  4. print(type(a))  
  5. print(type(name))  
  6. print(type(length))  
Output
 
Python Programming
 

Conclusion

 
There are two modes for executing Python programs - interactive mode and scripting mode. In interactive mode, the code gets executed line by line while in scripting mode, the entire script is prepared in the form of source and then it is executed.


Recommended Free Ebook
Similar Articles