Header Ads Widget

Responsive Advertisement

Barebones of a python Program : Fundamental of python program : Sumita Arora


In this Section we will discuss about basic structure of the python program - what all it can contain. Before we proceed, have a look at following sample code. Look at the code and then proceed to the discussion that follows. Don't worry if the things are not clear to you right now. They's will become clear when the discussion proceeds.


Various components of Python  program

  • Expressions 
  • Statements
  • Comments 
  • Blocks and Indentation

Expressions: An Expression is any legal Combination of symbols that represents a value. An Expression represents something, which python Evaluates and which then produces a values. 


Expression that are values only

12

23.4

67.8


Complex expressions that produces a values which evaluated.

a+5

(3+5)/4

Statements: While an expression represents something, a statements is a programming instruction that does something. Some action takes place. 

print("My First Python Program")

if b<66 :

While an Expressions is evaluated, a Statement is executed some action takes place. And it si not necessary that a statement results in a values: It is not necessary that a statement results in a value it may or nay not yield a value. 

a=25

b=a-5

print(a+10)

if b<5 :


Comments: Comments are the additional readable information, which is read by the programmers but ignored by the python interpreter. In Python, comments begin with the end of pyhsical Line. 

The line beginning with # are the full line comments. There are three full line comments in the program, which are:

#This program shows a program's components

Inline comment : It starts with a # in the middle of a physical line, after python code

Multi-line comments: 

You can enter a multi-line comment in Python code in two ways:

A) Add a # Symbol in the beginning of every physical line part of the multi-line comments

  # Multi-line comments are useful for detailed additional information.

  #Related to the program in question.

  #It helps clarity certain important things


B) Type comment as a triple-quoted multi-line string

'''

 Multi-line comments are useful for detailed additional information.

 Related to the program in question.

 It helps clarity certain important things

'''

This type of multi-line comment is also knows as docstring.

You can either use triple-apostorphe (''') or triple quotes(""") to write docstrings. The docstrings are very useful in documentation.


Block and Indentation: Sometime a group of statements is part of another statement or function. Such a group of one or more statements is called block or code-block or suite. For Example

if b<66 :

      print("Value of b is less than 66")

      print("Thank You.")

in If block  spaces before print statement is called indentation. All statements under if block is called Blocks 



python first program hello world python download python programming for beginners python code examples python programs for practice first python program in visual studio code What should my first Python project be? When did Python program start?

Post a Comment

0 Comments