Skip to main content

Basics of Python Programming

Basics of Python Programming

Python is an interpreted programming language. Python source code are compiled to byte code as .pyc file, and this byte code can be interpreted.
There are two modes for using the Python interpreter:
  1. Interactive Mode
  2. Script Mode

Interactive Mode

Without passing python script file to interpreter, directly execute code to Python prompt.
Example:
>>>2+6
Output:
8
The chevron in the beginning of the 1st line, i.e. the symbol >>> is a prompt the python interpreter uses to indicate that it is ready. If the programmer types 2+6, the interpreter replies 8.

Script Mode

Alternatively, programmers can store Python script source code in a file with .py extension, and use the interpreter to execute the contents of the file. To execute the script by the interpreter, you have to tell the interpreter the name of the file. For example, if you have a script name MyFile.py and you’re working on Unix, to run the script you have to type:
python MyFile.py
Working with interactive mode is better when Python programmers deal with small pieces of code as you can type and execute them immediately, but when the code is more than 2-4 lines, using the script for coding can help to modify and use the code in future.

Comments

For Programs Click Here

Popular posts from this blog

Syllabus

Syllabus  C Programming Tutorials C Tutorial C Introduction History of C Programming Language C Installation C Program Structure C Input and Output (I/O) C Format Specifiers Declaration & Assignments C Tokens C Identifiers C Keywords C Constants C Operators C Data Types C Variables C Preprocessors C Type Casting C Custom Header File Flow Control C Decision Making C if Statements C if-else Statements C Nested if-else Statements C else-if Statements C goto Statement C switch Statements C Loops C while loops C do while loops C for loops Functions C Functions C Function Arguments C Library Functions C Variable Scope Arrays & Strings C Arrays C Strings Pointers C Pointers C Dynamic Memory Allocation Structure & Union C Structures C Unions File I/O C File Handling C fopen C fclose C getc C putc C getw C putw C fprintf C fscanf C fgets C fputs C feof                                     ...

C++ Constructors and Destructors

C++ Constructors and Destructors Providing the initial value as described in the earlier chapters of C++ does not conform to the philosophy of C++. So C++ provides a special member function called the constructor which enables an object to initialize itself at the time of its creation. This is known as automatic initialization of objects. This concept of C++ also provides another member function called destructor which is used to destroy the objects when they are no longer required. In this chapter, you will learn about how constructors and destructors work, types of constructors and how they can be implemented within C++ program. What are constructors? The process of creating and deleting objects in C++ is vital task. Each time an instance of a class is created the constructor method is called. Constructors is a special member functions of class and it is used to initialize the objects of its class. It is treated as a special member function because its name is the same as the cla...

C if-else Statements

Flow Control C if-else Statements If else statements in C is also used to control the program flow based on some condition, only the difference is: it’s used to execute some statement code block if expression is evaluated to true, otherwise executes else statement code block. The basic format of if else statement is: Syntax: if ( test_expression ) { //execute your code } else { //execute your code } Figure – Flowchart of if else Statement: Example of a C Program to Demonstrate if else Statement  Example: #include <stdio.h> main () { int a , b ; printf ( "Please enter the value for a:" ); scanf ( "%d" , & amp ; a ); printf ( "\nPlease the value for b:" ); scanf ( "%d" , & amp ; b ); if ( a & gt ; b ) {    printf ( "\n a is greater" ); } else {    printf ( "\n b is greater" ); } } Program Output: Example: #include <stdio.h> main () { int num ; printf ( ...