Python Programming Language - Part 1

Introduction

Python is an example of a high-level language. Other high-level languages you might have heard of are C, C++, Perl, and Java. it is much easier to program in a high-level language. Programs written in a high-level language take less time to write. They are shorter and easier to read About python in deeply and installation.

You can download .py files of the following examples that directly execute if you have already installed Python in your Computer.

Download Python LanguageTutorials and give star on GitHub if that files are helpful for you.

Now I want to tell you about Coding Part of Python Programming Language:

  1. Simple Hello World Program
    1. # Comment    
    2.     
    3. print("Hello World"# print Hello World on Screen    
    4.     
    5. input() # Pause Console Screen   
    Output

    Hello World

  2. Variables

    Python programming language have same type of variable declaration conditions, but in this No One Keyword is used for declaration variables type.

    Example: int value ;

    Here int is not used in Python Programming Language for variable declaration.

    So I’m giving you full example of Variables:
    1. name = input("Enter Your Name..."# Take input from user    
    2.     
    3. print("Type",type(name), "\n"# print type of 'name' variable    
    4.     
    5. principle = 5000 # Assign Value to the variable    
    6.     
    7. print("Amount Type...", type(principle),"\n")    
    8.     
    9. rate = 10.5    
    10.     
    11. print("Rate Type...", type(rate) ,"\n")    
    12.     
    13. time = 3    
    14.     
    15. print("Time Type...", type(time) ,"\n")    
    16.     
    17. interest = principle * rate * time / 100 # Calculate Interest    
    18.     
    19. print("Interest Type...", type(interest) ,"\n")    
    20.     
    21. print("Hello ", name, "!\nInterest is=", interest)    
    22.     
    23. input()   
    Output

    Enter Your Name...NeErAj KuMaR
    Type <class 'str'>

    Amount Type... <class 'int'>

    Rate Type... <class 'float'>

    Time Type... <class 'int'>

    Interest Type... <class 'float'>

    Hello NeErAj KuMaR !
    Interest is= 1575.0

  3. Functions

    I’ll show simple math function and some other functions for performing the task.

    But when we want to perform some math function task, then ‘Import math’ library in Program.

    Example:
    1. import math # import Math    
    2.     
    3. def type_conversion(): # Definition of Function 'type_conversion'    
    4.     
    5.     print("Type Conversion Fucntions...\n")    
    6.     
    7.     print("32.53 Converted into int = ",int(32.53) ,"\n")    
    8.     
    9.     print("32 Converted into float = ",float(32) ,"\n")    
    10.     
    11.     print("32.53 Converted into string = ",str(32.53) ,"\n")    
    12.     
    13.     input("Press Enter for next function types\n\n")    
    14.     
    15. def mathfunction():    
    16.     
    17.     print("Math Fucntions...\n")    
    18.     
    19.     print("Firstly 'import math' \n")    
    20.     
    21.     print("About imported math file ... ",math ,"\n")    
    22.     
    23.     radius =0.7;    
    24.     
    25.     circumference=2*math.pi*radius    
    26.     
    27.     print("Circumference of Circle is : ",circumference ,"\n")    
    28.     
    29.     area=math.pi*math.pow(radius,2)    
    30.     
    31.     print("Area of Circle",area ,"\n")    
    32.     
    33.     input("Press Enter for see How to Add new Function? \n\n")    
    34.     
    35. def _simple_():    
    36.     
    37.     print("Hello I'm in Now _simple_() function \n")    
    38.       
    39.     print("print(_simple_)","show function Location of _simple_ ",_simple_ ,"\n")    
    40.     
    41.     print("Type(_simple_)"," show Type of _simple_ ",type(_simple_),"\n\n")    
    42.     
    43. def parameter(param):    
    44.     
    45.     print("Parameter is : ",param,"\n\n");    
    46.     
    47. def special_parameter(param):    
    48.     
    49.     print(param, "\n")    
    50.     
    51. def dou_parameter(value1,value2):    
    52.       
    53.     print("Addition of Value1 & Value2 is : ",value1+value2,"\n\n")    
    54.     
    55.     
    56. type_conversion() # calling function 'type_conversion'    
    57.     
    58. mathfunction()    
    59.     
    60. _simple_()    
    61.     
    62. val=input("Enter Any String...")    
    63.     
    64. parameter(val)    
    65.     
    66. special_parameter('parameter '*5# Special Parameter    
    67.     
    68. val1=input("Enter First Value...")    
    69.     
    70. val2=input("Enter Sscond Value...")    
    71.     
    72. dou_parameter(val1,val2)    
    73.     
    74. input()   
    Output

    Type Conversion Fucntions...

    32.53 Converted into int = 32

    32 Converted into float = 32.0

    32.53 Converted into string = 32.53

    Press Enter for next function types


    Math Fucntions...

    Firstly 'import math'

    About imported math file ... <module 'math' (built-in)>

    Circumference of Circle is : 4.39822971502571

    Area of Circle 1.5393804002589984

    Press Enter for see How to Add new Function?


    Hello I'm in Now _simple_() function

    print(_simple_) show function Location of _simple_ <function _simple_ at 0x027B06F0>

    Type(_simple_) show Type of _simple_ <class 'function'>


    Enter Any String...NeErAj KuMaR
    Parameter is : NeErAj KuMaR


    parameter parameter parameter parameter parameter

    Enter First Value...NeErAj
    Enter Sscond Value...KuMaR
    Addition of Value1 & Value2 is : NeErAjKuMaR

    So above example show some function type and their uses.

  4. Conditionals Statement

    In Python Programming Language, we have ”if” conditional statement but it don’t have switch/case in this language. Firstly, switch/case developed but after some time it was rejected.

    If you want to get full knowledge, read the article on the official website of Python.

    Example:
    1. def simple(x):    
    2.     
    3.     if(x > 0):    
    4.     
    5.     print("X is Positive Number \n")    
    6.     
    7. def alternate(x):    
    8.     
    9.     if(x>0):    
    10.     
    11.     print("X is positive Number \n")    
    12.     
    13.     else:    
    14.     
    15.     print("X is Negative Number \n")    
    16.     
    17. def chained(x):    
    18.     
    19.     if(x==0):    
    20.     
    21.     print("X is Zero \n")    
    22.     
    23.     elif(x>0):    
    24.     
    25.     print("X is Positive Number \n")    
    26.     
    27.     else:    
    28.     
    29.     print("X is Negative Number \n")    
    30.     
    31. value=input("Enter Value...")    
    32.     
    33. value=int(value)    
    34.     
    35. simple(value)    
    36.     
    37. alternate(value)    
    38.     
    39. chained(value)    
    40.     
    41. input()   
    Output

    Enter Value...5
    X is Positive Number

    X is positive Number

    X is Positive Number

    Enter Value...0
    X is Negative Number

    X is Zero

    Enter Value...-3
    X is Negative Number

    X is Negative Number

I’ll be back for another tutorial on Python Programming Language. I hope you will easily understand my code for learning the purpose of Python.

Up Next
    Ebook Download
    View all
    Learn
    View all