Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/ekhaliya/public_html/topcse/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: Cannot modify header information - headers already sent by (output started at /home/ekhaliya/public_html/topcse/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php:340) in /home/ekhaliya/public_html/topcse/wp-content/plugins/sg-cachepress/core/Supercacher/Supercacher_Helper.php on line 77
python introduction with Top CSEtopcse.com -:- Top CSE

Introduction to python


Guido Van Rossum invented the python programming language in 1990’s.Python is a high level language for solving problems on modern computer systems. Python program can run on any operating systems and it is an interpreted language.

Python expressions and statements can run in interactive programming environment called “shell”. The easiest way to open a python shell is to launch the idle. This is an integrated program development environment that comes with the  installation.


A shell window contains an opening message followed by the special symbol “>>>”, called a shell prompt. In python  The cursor at shell prompt waits for you to enter a python command.

>>> 3+4            #program to print sum of numbers on idle screen

output : 7


output : 3

>>>”python”      #to print a string 

output : Python

>>>Name =”Kiel” 

>>> Name

output :  Kiel

>>>print (“hi”)     # program to print something i.e print message “hi”

output: hi


output:  hello Kiel

this language is a case sensitive language. The   print function always ends its output with newline. therefore,  In other words, it displays the values of the expression, an then it moves the cursor to the next line on the console windows.

To begin the next operation on the same line as the previous one , you can place expression end=” “, which says end the line with an empty string at the end of the list of expressions print (expression, end=””);

You can prompt user to enter a value from the keyboard using the input (““) function.


In python comments are written using # for single line comment and  triple quotes “”” “”” for multiple line string . a comment is a piece of program text that the interpreter ignores but provides useful documentation to the programmers .

End of line comments : these comments begin with # symbol and extend to end of line .

example : #hi hello ( a single line comment)

doc string : multi line  string of the form    “”” hi hello how r u………………………………………………………………..”””


>>> name=input(“enter name:”  #program to take input from the user 

output :

Enter name: Tamra


output: ‘Tamra

>>>Print (name)

output : Tamra

The input function always builds a string from the user’s keystrokes and returns it to program. After inputting strings that represents numbers, the programmer must convert them from strings to appropriate numeric types.

  1. Int (a string of digits):- convert a string of digits to integer value.
  2. Float (a string of digits):- convert a string of digits to a floating point values.

at any point you may save the file key selecting file/save . if you do this you should use “.py” extensions .

example : hello.py


how python works

figure 1. how python works

  1. python is object oriented programming language  and an  interpreted language. python converts its machine code into byte code . this byte code is interpreted and executed by  PVM (python virtual machine) .
  2. The Python interpreter performs following tasks to execute a Python program :

  • 1 : here the  interpreter reads a python code  verifies  its each line.If gets any error, shows an error message.
  • 2 : so  , If we get  no error then interpreter translates it into “Byte code”.
  • 3 :  then the ,Byte code is sent to the Python Virtual Machine(PVM).Here the byte code is executed on PVM  and If an error occurs then it an error message.


  1. Data type : consist of a set of values and a set of operations that can be performed on those values .
  2. Literal : literal is a way  a value of a data type looks to a programmer .
  3. Literal constant : the value of literal constant can be used directly in the program .moreover it is a constant because its value cannot be changed .example : 1,2,’a’ and “hello”.therefore ,we have three types of data type named as  integer as int ,float and character strings as str .
  4. Built in format() functions :-


output : 5.3333333

>>>format (float(16\float(3)), ‘.2f’)


here , ‘.2f’ in the format() function rounds the result to two decimal places of accuracy in the string produced .

Dividing the integers:

dividing any two integers producing a floating point  number.


output : 3

therefore, a float is also produced by performing  an operation  on two floats or on float and integer .


output : 15.0

Quotient and Remainder :

when we are dividing two numbers , and , if we want to know the quotient and remainder , use the floor division (//) and modulo operator (%) respectively .

>>> 78//5

output :15


output : 3

Exponentiation : 

besides +.-,* and /  also supports ** operator . so,the ** operator is used for exponentiation , and  it is used for  raising of one number to the power of another .


output : 125



%d bloggers like this: