Note :  To do python programming or to run python programs please use Software Python IDLE 2 OR Python IDLE 3  for new learners .

   Tprograming suggest these two IDLE'S for better and easy performance .

   You can use Visual Code also.

 

Difference between Programming language and Scripting language :-






What are Gluing existing applications ?


      • A script that glues existing components to form a new application which needs a Graphical User Interface (GUI) , is an gluing existing application .
      • There are two ways to build gluing existing applications .
      • i.e first is launch stand-alone programs and let such programs communicate through files and 
      • second is making the script call functions in the applications .

Impactful / productive pairs of programming languages :-

      • Java & JavaScript
      • PHP & Java
      • C & C++
      • Unix & C

Features of Python :-

      • Object - oriented 
      • Class & object
      • Code - reusability 
      • simple 
      • easy to learn
      • Big standard library
      • Scalable
      • Portable
      • Dynamic
      • GUI programming
      • Database 
      • Interactive


Applications of Python :

      • Web applications
      • Software development 
      • Business applications
      • Console based applications
      • GUI based desktop applications
      • Scientific and numeric applications
      • 3D CAD applications 
      • Enterprise applications
      • Education


Limitations / Disadvantages of Python :-

      • Weak for mobile programming
      • More Runtime error
      • More memory occupation
      • Slow speed
      • Hard to use in another languages 
      • Difficult GUI programming

Implementations of Python :-

      • JPython :Written in Java 
      • CPython : Written in C
      • IornPython : Written in C#
      • RubyPython : Wriiten in Ruby
      • Brython : Written for browser python
      • MicroPython : Written microcontroller

Python file Extensions :-

      • py: The normal extension for a Python source file, regular script.
      • pyc: The compiled bytecode.
      • pyd: A Windows DLL file.
      • pyo: A file created with optimizations.
      • pyw: Python script for Windows.
      • pyz: Python script archive.


Python identifiers :-

A python identifier is the name used to identify a variable , function , class , module or other object .

valid identifiers :    abc , salary_2022 , Empsalary 

 

Rules for Writing identifiers :- 

·      Identifiers can be a combination of letters in lowercase (a to 2) or uppercase (A to Z) or digits (0 to 9) or an underscore).   Names like myClass, var 1 and print this to screen, all are valid example

·   An identifier cannot start with a digit. 1variable is invalid, but variable is perfectly fine.

·   Keywords cannot be used as identifiers.

·   Python does not allow punctuation characters such as [#, @, $, and % within identifiers.

·   Spaces are not allowed as part of an identifier.

·   Identifier can be of any length.

·   Python is a case sensitive programming language. That means Name and name are two different identifiers in Python. 


Python keywords :-

Python keywords are reserved word or pre-defined words or system defined words are used to write a program with its specific use .




Data Types :  Data types are used to show which type of data we are using in a program .

There are main 7 main daa types of python :

        1. int : used to store integers lie 1 2 3 
        2. float : used to store single decimal integers like 1.2 3.4 35.9
        3. boolean : used to show value i terms of true or false 
        4. Strings : used to store characters 
        5. tuple : ordered immutable sequence of values
        6. list : ordered mutable sequence of values 
        7. dictionary : unordered paires of values

Comments in Python :-

      • Single line comment : 
Example : #This is single line comment in Tprograming.com

      • Multi-line comment :
Example : """This is multi line comment inTprograming.com


Indentations in Python :-

    • Python provides no braces to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation, which is rigidly enforced. 

    • The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount.

Example : 

if(t>0)

    print("t")

else

   print("No t") 

 

Input / Output function inpython :-


Output function : print() - used to print any message or output

Example : 

>>>t=25
>>>print('Value of t is ',t)

Output : Value of t is 25

Input() function : It is used to accept value from user

Example :

>>>t=input('Enter value for t : ')
>>>print('Value of a is : 't)

Output : 

Enter value for t : 5

Value of t is : 5

Example : 

               print (1,2,3,4)

               print(3,2,3,4,sep="*)

               print(1,2,3,4,sep="",end-'&')

Output : 

                  1 2 3 4

               1*2*3*4

               1#2#3#4&

How to format output ?

str.format() : We can format our output using this function 

example 1 :

p=20 

q=40

print("value of p is () and value of q is ()".format(p,q)) 

Output :

value of p is 10 and value of q is 40

Example 2 :

print("my name is {0} and my founder name is {1}".format("Tprograming","Darshan"))

Output :

my name is Tprograming and my founder name is Darshan

eval() function :-    

It is used for calculations .   

Example :  

>>>eval(5+6) 

Output : 11

Command line arguments in python :

In python command line arguments are used to pass input at run time 

There are main basic three options to read command line arguments in python 

        1. Python getopt module
        2. Python sys.argv
        3. Python argparse module

1. Python getopt module :

Syntax/Example : 

import getopt

import sys 

argv sys.argv[1:]

try:

opts,args=getopt.getopt(argv,'hm:d',['help,my_file='])

print(opts)

print(args)

print("something went wrong")

sys.exit(2)

 

2. python sys.argv : This module stores arguments in the form of list

syntax/example :

       import sys

                     print('Arguments:, len(sys.argv))

                     print("List:, str(sys.argv))

                     if sys.argve 2

                           print('To few arguments, please specify a filename")

                     filename = sys.argv[1]

                     print("Filename: filename) 

 

3. python argparse module :

syntax/example : 

import argparse

                         parser =  argparse.ArgumentParser()

                         # define the various command-line options

                          parser add argument(‘-0’, ‘--open-file', help= ‘Description', required=False)

                          parser.add_argument(‘-s’,‘--save-File’, help= ‘Description', required=False)                 

                          args = parser.parse_args()

                           print(args.open_file)

                           print(args.save_file)