Q
Python Programming | Sample Programs
Home » Embedded Systems » Python Programming | Course Home » Python Programming | Sample Programs

Python Programming – Sample Programs

 Sample programs is the first step you take to transition from theory to practical. These simple python program examples typically demonstrated in a classroom will ensure you are able to immediately see it running in front of your eyes. Added to that our mentors will provide you some exercises where you will be modifying the code in the class itself. By doing this fill-in-the-blank approach, will take out your fear of coding.

Brief:

In Python, We can write comments in different ways. This program  demonstrates the writing comments in single line as well as multiple lines.

Source Code:

Simple Python Program Example output:

Simple Python Program Example output:

Brief:

In Python, we can use complex numbers. This program demonstrates how to add two complex numbers

Source Code:

Example output

Embedded Systems Course | Emertxe | Bangalore

Brief:

If we want to print value of variable in specific datatype, then it can be implemented as shown below

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrate the conversion of octal, binary and hexadecimal to decimal

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bangalore

Brief:

This program demonstrate the conversion of string to other base value

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrate the conversion of integer to other base value

Source Code:

Example output:

Embedded Systems Course | Emertxe| Bangalore

Brief:

This program demonstrate the Boolean datatype. We can write conditions in print, based on the output True or false, it will print the value.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrate the different ways of initializing the strings.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bangalore

Brief:

This program demonstrate the slicing operator.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrate the repetition of strings.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrate the creating byte type array and read and display the items.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrate the creating byte type array and read and display the items.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrate the creating the list and accessing the elements from list.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrate the creating the tuple and printing the elements of tuples.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrate the different operations using the range().

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrate the different operations using the type().

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the // operator.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the assignment operator.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the Unary ‘-‘ operator.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the relational operator.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the logical operator.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the Short Circuit Evaluation.
Short circuit evaluation means second condition will not be evaluated based on first condition.
In case of ‘and’ operator if first condition is false then no need to check second one.
In case of ‘or’ operator if first condition is true then no need to check second one.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the Boolean Operator where value will be either TRUE or FALSE.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the Bitwise Operator.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the Membership Operator.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of Membership Operator.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of identity Operator – id().

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of relational Operator – ‘==’.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of Math library function.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of import with Math library function.

Source Code:

Example output:

Brief:

This program demonstrates the usage of import with Math library function.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of import with Math library function.

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of print function.

Source Code:

Example output: 

Brief:

This program demonstrates the usage of print function with attributes ‘sep’ and ‘end’.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of print function with objects.

Source Code:

Example output: 

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of print function with variable list.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of print function with formatted string.

Source Code:

Example output: 

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of input() function which is used to read input from user.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of input() function to read a character from user.

Source Code:

Example output: 

Embedded Systems Course | Emertxe |Bengaluru

Brief:

This program demonstrates the usage of input() function to read a integer from user.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of input() function to read multiple line from user.

Source Code:

Example output: 

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of eval() function.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

This program demonstrates the usage of eval() function.

Source Code:

Example output: 

Brief:

This program demonstrates access of command line arguments.

Source Code:

Simple Python program Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates access of command line arguments to add two numbers.

Source Code:

Example output: 

Simple Python Program Example output:

Brief:

This program demonstrates access of command line arguments to square a given number.

Source Code:

Simple Python program Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

As we all know that a program generally execute in an sequence unless and until we have some condition to change the flow of execution. Python Programming Language supports different flow conditions. This program demonstrates if condition.

Source Code:

Example output: 

Simple Python Program Example output:

Brief:

As we all know that a program generally execute in an sequence unless and until we have some condition to change the flow of execution. Python Programming Language supports different flow conditions. This program demonstrates if condition.

Source Code:

Simple Python program Example output:

Embedded SYstems Course | Emertxe | Bengaluru

Brief:

As we all know that a program generally execute in an sequence unless and until we have some condition to change the flow of execution. Python Programming Language supports different flow conditions. This program demonstrates if condition.

Source Code:

Example output: 

Simple Python Program Example output:

Brief:

As we all know that a program generally execute in an sequence unless and until we have some condition to change the flow of execution. Python Programming Language supports different flow conditions. This program demonstrates the while loop.

Source Code:

Simple Python program Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

As we all know that a program generally execute in an sequence unless and until we have some condition to change the flow of execution. Python Programming Language supports different flow conditions. This program demonstrates the for loop.

Source Code:

Example output: 

Simple Python Program Example output:

Brief:

As we all know that a program generally execute in an sequence unless and until we have some condition to change the flow of execution. Python Programming Language supports different flow conditions. This program demonstrates the for else loop.

Source Code:

Simple Python program Example output:

Simple Python Program Example output:

Brief:

As we all know that a program generally execute in an sequence unless and until we have some condition to change the flow of execution. Python Programming Language supports different flow conditions. This program demonstrates the for else loop.

Source Code:

Example output: 

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of break inside loops. If break is executed control will come out from the loop. 

Source Code:

Simple Python program Example output:

Embedded Systems course | Bangalore | Emertxe

Brief:

This program demonstrates the usage of continue inside loops. If continue is executed, then that particular cycle will be skipped and jump to condition evaluation.

Source Code:

Example output: 

Simple Python program Example output:

Brief:

This program demonstrates the usage of pass inside loops. If loop doesn’t contains any statement, then pass will be used to mention nothing..

Source Code:

Simple Python program Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of pass inside loops. If loop doesn’t contains any statement, then pass will be used to mention nothing..

Source Code:

Example output: 

Simple Python program Example output:

Brief:

This program demonstrates the usage of assert keyword.

Source Code:

Simple Python program Example output:

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates the usage of assert keyword.

Source Code:

Example output: 

Simple Python program Example output:

Brief:

This program demonstrates of creating ang printing array elements. In programming array is a collection of elements.

Source Code:

Example output: 

Embedded Systems Course | Emertxe | Bengaluru

Brief:

This program demonstrates of creating ang printing array elements. In programming array is a collection of elements.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates of creating ang printing array elements. In programming array is a collection of elements.

Source Code:

Example output: 

Brief:

This program demonstrates of creating ang printing array elements. In programming array is a collection of elements.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates array index. By using index you can retrieve the items of an array.

Source Code:

Example output: 

Brief:

This program demonstrates array index. By using index you can retrieve the items of an array.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the array slicing. It will give you the subset of array from given start and end point.

Source Code:

Example output: 

Brief:

This program demonstrates the different array methods.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the population of array elements.

Source Code:

Example output: 

Brief:

This program demonstrates the creation of an array using numpy. 

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the creation of an array using numpy. 

Source Code:

Example output: 

Brief:

This program demonstrates the creation of an array using numpy. 

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the creation of an array using numpy. 

Source Code:

Example output: 

Brief:

This program demonstrates the creation of an array using numpy. 

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the creation of an array using numpy. 

Source Code:

Example output: 

Brief:

This program demonstrates the creation of an array using linespace. 

Source Code:

Example output: 

Brief:

This program demonstrates the creation of an array using logspace. 

Source Code:

Example output: 

Brief:

This program demonstrates the creation of an array using arrange(). 

Source Code:

Example output: 

Brief:

This program demonstrates the creation of an array using zeros() and ones(). 

Source Code:

Example output: 

Brief:

This program demonstrates the mathematical operations on array.. 

Source Code:

Example output: 

Brief:

This program demonstrates the comparison between 2 arrays.

Source Code:

Example output: 

Brief:

This program demonstrates the comparison between 2 arrays.

Source Code:

Example output: 

Brief:

This program demonstrates the comparison between 2 arrays.

Source Code:

Example output: 

Brief:

This program demonstrates the comparison between 2 arrays using where().

Source Code:

Example output: 

Brief:

This program demonstrates the aliasing arrays in python.

Source Code:

Example output: 

Brief:

This program demonstrates the copying arrays in python.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the view on arrays in python.

Source Code:

Example output: 

Brief:

This program demonstrates the slicing of arrays in python.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the ndim of arrays in python.

Source Code:

Example output: 

Brief:

This program demonstrates the shape attribute of arrays in python.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the shape attribute of arrays in python.

Source Code:

Example output: 

Brief:

This program demonstrates the size of items in arrays in python.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the reshaping arrays in python.

Source Code:

Example output: 

Brief:

This program demonstrates the 2 dimensional arrays in python.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the 2 dimensional arrays in python.

Source Code:

Example output: 

Brief:

This program demonstrates the various ways of assigning string to variables.

Source Code:

Example output:

Brief:

This program demonstrates the various ways of formatting string using format specifiers.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the len() function which is used to find the length of the strings.

Source Code:

Example output: 

Brief:

This program demonstrates the traversing string using index.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the repeating string in  python.

Source Code:

Example output: 

Brief:

This program demonstrates the concatenating 2 strings in  python.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the membership operate of strings in  python.

Source Code:

Example output: 

 Brief:

This program demonstrates the strings comparison in  python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the space removal from strings in  python.

Source Code:

Example output: 

 Brief:

This program demonstrates of finding substring in given strings in  python.

Source Code:

Example output: 

 Brief:

This program demonstrates of finding substring in given strings in  python.

Source Code:

Example output: 

 Brief:

This program demonstrates replacing the strings in  python.

Source Code:

Example output: 

 Brief:

This program demonstrates splitting the strings in  python.

Source Code:

Example output: 

 Brief:

This program demonstrates joining the strings in  python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the changing case of the strings in  python.

Source Code:

Example output: 

 Brief:

This program demonstrates the functions in python. This function fins the sum of numbers. 

Source Code:

Example output: 

 Brief:

This program demonstrates the return statement of functions in python. This function fins the sum of numbers. 

Source Code:

Example output: 

 Brief:

This program demonstrates the return statement of functions in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the concatenation of 2 strings using functions in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the nested functions in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the function as parameter to another function in python. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the returning function in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the variable scope inside the function in python. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the modification of list inside the function in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the modification of list inside the function in python. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the positional arguments inside the function in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the keyword arguments inside the function in python. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the default value inside the function in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the variable length of the function in python. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the variable length of the function in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the global variable of the function in python. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the global variable of the function in python. 

Source Code:

Example output: 

 Brief:

This program demonstrates the global variable of the function in python. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the pass group items through list into function and return multiple values. 

Source Code:

Example output: 

 Brief:

This program demonstrates the pass group items through list into function and return multiple values. 

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the recursive function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the lambda function in python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the decorators of function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the decorators of function in python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the decorators of function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the generators of function in python.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the generators of function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the code to display a message if function name is ‘_main_’.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the calculation of salary by using function in python.

Source Code:

Example output: 

 Brief:

This program demonstrates the creation of list with different types of elements.

Source Code:

Example output: 

 Brief:

This program demonstrates the creation of list with different types of elements using range().

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the updating the list with different types of elements.

Source Code:

Example output: 

 Brief:

This program demonstrates the finding item in list.

Source Code:

Simple Python program Example output:

 Brief:

This program demonstrates the retrieving details of employees from list.

Source Code:

Example output: 

Brief:

This program demonstrates the finding square of a numbers and updating the list.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the finding square of numbers between 1 to 10 and finding the even number from result.

Source Code:

Example output: 

Brief:

This program demonstrates the adding 2 list elements one by one.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates the adding 2 list elements one by one.

Source Code:

Example output: 

Brief:

This program demonstrates the basic operations on tuples.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates adding elements to the tuples.

Source Code:

Example output: 

Brief:

This program demonstrates creating dictionary for employees.

Source Code:

Example output: 

Brief:

This program demonstrates reading from dictionary.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates reading from dictionary.

Source Code:

Example output: 

Brief:

This program demonstrates converting list into dictionary.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates converting string into dictionary.

Source Code:

Example output: 

Brief:

This program demonstrates creating ordered dictionary.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates how to write and create the object.

Source Code:

Example output: 

Brief:

This program demonstrates about constructor of class.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates about instance variable of class.

Source Code:

Example output: 

Brief:

This program demonstrates about class variable.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates about class namespace.

Source Code:

Example output: 

Brief:

This program demonstrates about instance namespace.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates about instance methods.

Source Code:

Example output: 

simple python program examples

Brief:

This program demonstrates about mutator and accessor.

Source Code:

Simple Python program Example output:

Embedded Systems Course | Bangalore | Emertxe

Brief:

This program demonstrates about methods of class

Source Code:

Example output: 

simple python program examples

Brief:

This program demonstrates about static methods of class

Source Code:

Example output:

Embedded Systems Course | Emertxe | Bangalore

Brief:

This program demonstrates about static methods of class

Source Code:

Example output:

simple python program examples

Brief:

This program demonstrates about passing one class members to another

Source Code:

Simple Python program Example output:

Embedded Systems Course | Emertxe | Bangalore

Brief:

This program demonstrates about writing a class inside another class.

Source Code:

Example output: 

Brief:

This program demonstrates about writing a class inside another class.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates about inheritance in python.

Source Code:

Example output: 

Brief:

This program demonstrates about inheritance in python.

Source Code:

Simple Python program Example output:

Brief:

This program demonstrates about inheritance in python.

Source Code:

Example output: 

Brief:

This program demonstrates about inheritance and constructor of base class and sub class.

Source Code:

Simple Python Program Example output:

Brief:

This program demonstrates constructor overriding in python.

Source Code:

Example output: 

Brief:

This program demonstrates about super method of a class.

Source Code:

Simple Python Program Example output:

Q