Python: Reading Input from the Console

♠ Posted by Unknown in

Reading Input from the Console in Python



The input() function asks the user to input a value for the variable. Default value entered as a string. 

Python: Writing a Simple Program

♠ Posted by Unknown in

Writing a Simple Program in Python


Start Python IDLE from Start menu à Python Group. Write a program in New File window as shown below.

Python Sample Program

Run program, Select Run (F5) from Run menu.

Output:


>>> ========RESTART =========
>>> 
The Area of Circle :  1256.0

Python: Comments

♠ Posted by Unknown in

Comments in Python


In Python, comments are preceded by a pound sign (#) on a line, called a line comment, or enclosed between three consecutive single quotation marks (''') on one or several lines, called a paragraph comment. When the Python interpreter sees #, it ignores all text after # on the same line. When it sees ''', it scans for the next ''' and ignores any text between the triple quotation marks.

For Example:

# This program displays one message


''' This program displays
   Two messages
'''

Line Continuation Symbol in Python

In some cases, the Python interpreter cannot determine the end of the statement written in multiple lines. We can place the  line continuation character (\) at the end of the line to tell the interpreter that the statement is continued on the next line. For example, the following statement

fact = 1 * 2 * 3 * 4 * \
          5 * 6
is equivalent to
fact = 1 * 2 * 3 * 4 * 5 * 6

Python: Creating Source Code Files

♠ Posted by Unknown in

Creating Source Code File in Python


Entering Python Statement at the statement prompt >>> is convenient, but the statements are not saved. To save statements for later use, you can create a python file to store the statements. The file can be created using editor, that file is called a Python source file or script file, or module. By convention, Python files are named with the extension .py.

Running a Python program from a script file is known as running Python in script mode. Typing a statement at the statement prompt >>> and executing it is called Python in  interactive mode.

To create new Python file in IDLE, select file menu à New File. It opens new file window type following lines and save it as “Example01.py”. Now Click Run (F5) from Run menu of window. Control transfer to IDLE statement prompt and show the output.



Example:

Example01.py

#Display two messages
print(“Welcome to world of Python…”)
print(“Hello Friends…”)


Python: Getting Started

♠ Posted by Unknown in

Getting Started with Python


Let’s get started by writing a simple Python program that displays the message “Welcome to world of Python…” on the console.

Assume you have Python installed on the OS. You can start Python in a command window by typing “Python” at the command prompt, as shown in below figure. Or by using IDLE, as shown in another figure. IDLE (Interactive DeveLopment Environment)is an Integrated Development Environment (IDE) for Python.

Python Command line figure


Python command-line and IDLE can also be accessed directly from the Windows Start menu and in Python group.

Python IDLE window

Python: History

♠ Posted by Unknown in

Python: History

                   
Since 1990, Python was created by Guido van Rossum in the Netherland and was named after well-known British Monty Python’s Flying Circus. Rossum developed Python as a hobby, and Python has become a popular programming language widely used in industry and academia due to its simple, concise, and intuitive syntax and extensive library.

Python is a general-purpose programming language. That means you can use Python to write code for any programming task. Python is now used in the Google Search Engine, in mission-critical projects at NASA, and in transaction processing at the New York Stock Exchange.

Python is interpreted, which means that Python code is translated and executed by an interpreter.

Python is an  object-oriented programming (OOP) language. Data in Python are objects created from classes.