Skip to main content

P

1) High level prog. language
2) Python is work quickly and integrate system more efficiently.
3) Python are simple and easy, portable build in data structure and open sources.
4) Python is high level interpreted, interactive and object oriented scripting language.
5) Python is designed to high readable.

::Interpreted::  
1) Python is processed at run time by interpreter.
2) Not need to compiler your program before executing it.

::Interactive:: You can actually sit at a python prompt and interact with interpreter directly to write your program.


::Object Oriented::  Python supports objects oriented technique of    programming that encapsulates code within object.
Characterizes:-
1) Python supports functional, structured program as well as OOP's.
2) Python is used as Scripting language.
3) It can be compiled to Byte code for building large application.
4) It provides high level dynamic data type and support automatic garbage collection.




Application of Python:-
1) Easy-to-learn:- Python has few keywords, structures and and defined syntax.
2)Easy-to-read:- Python code is more clearly defined and visible to the eyes.
3)Easy-to-maintain:- Python source is fairly easy to maintain.
4)Portable: Python can run on a wide variety of hardware platform and same interface on all platform.


Command-line Option's:-
-d Provides debug input
-o Generate optimized Byte code
-s Do not run import site to look   
-x Disable class built in exception
-c cmd Run python script sent in cmd string
File Run python script from given file

Keywords:-
Its is reserved words that can't change during execution.
if
else
while
and 
assert
raise 
yield
break
class
continue
def
del
return
elif
except
exec
finally
for
try 
form
global
import
in
is
while
lambda
not 
or
pass
print
with

Notes:-
1) Python provides no-braces to indicate block of code for class and function,
2)Comments in python that # (hash) is not inside string being a comments.



command line arguments:-
Python enable you to do commands line arguments with -h-
$python -h                         
-c cmd :prog passed in as string   
    -d :debug output               
    -E :Ignore environment variable
    -h :print help message and exit



Variable

  • Variable is reserved memory location to store value.
  • Data type of variable, the interpreter allocated memory and decides, what can be stored in reserved memory.

Data type
1) Number
   a) int
   b) long
   c) float
   d) complex
2) String
3) List
4) Tuple
5) Dictionary

(1)Number: Stored numeric value's, number object are created,                   when you assign a value.
           var1=20
           var2=10

(2)String: Set of character's represented quotation marks.
              
         e.g HelloWorld 
          0-H 
          1-e
          2-l 
          3-l
          4-o
          5-W
          6-o
          7-r
          8-l
          9-d
          10-\0 null pointer

#program about string

#! /user/bin/python
str="Hello World"
print str-------print complete string
print str[0]----print first character  H
print str[2:5]---print 3rd to 5th char llo
print str[2: ]---print 3rd starting to end lloWorld
print str *2-----print two line's helloWorld HelloWorld
print str +"Test"--Print concatented string---HelloWorld Test

* asterisk sign:- string is repetition operator
+ plus     sign:- string concatenation operator


(3)List:-
  •  A list contain item's separated by common and enclosed within square brackets [].
  • List are similar to array in C-language.
  • Diff between array ad list is stored different data type together.
  • Value stored in list can be accessed using Slice operator [] and [:] with staring at 0.
#Program about list
#!/user/bin/python
list=['Mohit',8927,3.57,'Vicky',70.2]
tinylist=[123,"Vicky"]
print list-------Print complete list
print list[0]----print first element Mohit
print list[1:3]--print starting from 2rd to 3rd--8927,3.57
print list[2: ]--print element starting from 3rd element 
print tinylist *2--print list two times
print list +tinylist---Print concatenated list

(4)Tuple:-

  • Its is similar to list.
  • Tuple consists of number of value separated by commons.

#! /usr/bin/python
tuple=('abcd',786,2.23","Mohit",70.2)
tinytuple=(123,'Mohit')
print tuple      #print completed list
print tuple[0]   #print 1st element ---abcd
print tuple[1:3] #print staring 2rd till 3rd--7862.23
print tuple[2: ] #print element starting from 3rd
print tinytuple *2     #print list two times
print tuple +tinytuple #print concatenated lists  

Diff between Tuple & List:
>> Tuple are enclosed in brackets [] and their size can be changed and tuple can be though read only lists.
>> List are enclosed in parentheses () and can't changed.

(5)Dictionary:-

  • Python dict are kind of hash table type.
  • They work like associative arrays.
  • Dict key can be almost python type,but are usually number of string.
  • Dict are enclosed by curly braces {} and value can assigned & accessed using square braces [].

#program about dict
#!/usr/bin/python
dict={}
dict['one']="This is One"
dict[2]="This is Two"
tinydict={'name':'Mohit','code':6734,'dept':'IT'}
print dict['one'] #print value 'one' key---This is one
print dict[2]     #print value '2' key----This is two
print tinydict    #print completely dictionary
print tinydict.key()    #print all the key
print tinydict.values() #print all the value



Data type Conversion
  • To convert between type's, you simply use type name of a function.
  • Build in function to perform conversion from one data type to another.
  • Its is return a new object representing the converted value.


  • int (x[,base])   converts x to integer and base specifies base if x is string.
  • long(x[,base]) converts x to long integer and base specific base,if x is string.
  • float(x)           convert x to floating point number
  • complex(read[,imag]) Creates a complex number
  • str(x) Converted object x to string represent 
  • repr(x) Converted object x to expression string
  • eval(str) Evaluates string and return object
  • tuple(s)converted s to tuple 
  • list(s)  converted s to list
  • set(s)  converted s to set
  • dict(d) Created a dict, d must be a sequence of(key,value) tuple's.
  • chr(x)  Coverts integer to characters
  • ord(x)  Coverts integer to integer to unicode character
  • hex(x) Converts integer to hexadecimal
  • oct(x)  Converts integer to Octal string
Operator's

(1)Arithmetic + - * / o/o--module **--Exponent  //--floor_division
(2)Relational == != <> >< >= <=
(3)Assignment = += -= *= /= %= **= //=
(4)Logical    & / ~ ^ << >>
(5)Bitwise    AND OR NOT
(6)Membership:- is a sequence such as string,list and tuple
   in evaluate to true--Variable specified seq & false otherwise
   not in evaluate to true--if doesn't find a variable specified       sequence and false otherwise.
(9)Identify:-Compare the memory location of two objects.
   is evaluate to True if variable on either side of operator point to some object and false operator.
   is not evaluate to false is variable on either side some object and true other.

Operator Precedence

**           Exponentiation(raise of power)
~ + -      Complement,Unary plus,minus
* / % // multiply divide module floor_division 
+ -          Addition Substraction
>> <<   right and left bitwise shift
&           Bitwise AND
^|          Bitwise exclusive OR, regular OR
<= < > >= Comparison operator
<> == != Equality operator
= %= /= //= -= += *= **= Assignment 
is ,is not Identify operator
in, in not membership/Logical operator 

Decision Making

Decision structure evaluate multiple expression which produce true or false as outcome.
If statement consists of a Boolean expression followed by One or more statement.
If--else statement can be followed by optional else statement which execute when Boolean expression is false.
nested_if statement, you can use if or else if statement inside another if or else if statement.

if(single_statement):-If clause consists only of a single line,it may go on same line as header statement.

#! /usr/bin/python
var=100
if(var==100):print "value of expression is 100"
print "Good Bye"

Loop statement
  • In general statement are executed sequentially.
  • First statement in function is executed first,followed by second and so on.
  • There may be situation, when you need to execute a block of code several number of times.

(1)While_loop:- Repeats a statement or group of statement while is given condition is true. It tests the condition before executing the loop body.

(2)For_loop:- Executes a sequence of statement multiple times that manages the loop variable.

(3)Nested_loop:-You can use one or more loop inside. Only another while,for,or do--- while loop.

while loop:- 

while expression:
    statement(s) 

#prog. for while loop
count=0
while(count<3)
          count=count+1
               print("Hi Mohit")

For_loop

for iteration_var in sequence:
        statement(s)

#prog about for loop
print ("List Itension")
      l=["geeks","for","greeks"]
for i in l:
       print(i)

Using else statement with for loop:-
  • We can also combine else statement with for loop like in while loop.
  • But as no condition in for loop based on which the execution will terminate.
#Prog with combining else
list=["geeks","for""geeks"]
for index in range (len(list))
          print list[index]
else
          print"Inside else block"



Nested loop:-

for interation_var in sequence:
      for interator_var in sequence:
          statement(s)
          statement(s)

while expression:
      while expression:
              statement(s)
              statement(s)

Loop control statement:-

  • Continue
  • break
  • pass


  1. Loop control statement change execution from its normal sequence.
  2. When execution leave a scope, all automatic leave a scope, all automatic object that created in scope are destroyed. 

(1)Continue:- Its returns the loop control to the beginning of loop.
        #print all letters except 'e' and 's'
        for letter=='e' or letter=='s':
           continue
              print"Currnet letter:",letter
              var=10
   o/p: g k f o r g k

(2)Break:- Its is bring control out of loop.
         for letter in "geeksforgreeks"
              #Break the loop as soon its seen 'e' or 's'
              if letter=='e' or 'letter=='s':
                 break
              print"Current letter:",letter
    o/p: e
(3)Pass:- We use pass statement to write empty loop, pass is also              used for used for empty control in function and class.
          #An empty loop
          for letter in "greekforgreeks":
          pass
          print "Last letter:",letter

     o/p: s    


  • range() – This returns a range object (a type of iterable).
  • xrange() – This function returns the generator object that can be used to display numbers only by looping. Only particular range is displayed on demand and hence called “lazy evaluation“



































           



























Comments

Popular posts from this blog

#110 Mavanuru Malleshwara Temple

  Mavanuru Malleshwara Temple is located in Hassan district of Karnataka, This place is 30KM away from Hassan main town and 170KM from Bangalore. เคฎเคตเคจुเคฐु เคฎเคฒ्เคฒेเคถ्เคตเคฐ เคฎंเคฆिเคฐ เค•เคฐ्เคจाเคŸเค• เค•े เคนाเคธเคจ เคœिเคฒे เคฎें เคธ्เคฅिเคค เคนै, เคฏเคน เคœเค—เคน เคนाเคธเคจ เคฎुเค–्เคฏ เคถเคนเคฐ เคธे 30KM เค”เคฐ เคฌैंเค—เคฒोเคฐ เคธे 170KM เคฆूเคฐ เคนै। The temple is perched on top of a hill with beautiful views of the town, mountains and windmills all around. Though a small one, it looks stunning in bright golden colour and houses Lord Shiva as the deity.  เคฎंเคฆिเคฐ เคเค• เคชเคนाเคก़ी เค•ी เคšोเคŸी เคชเคฐ เคธ्เคฅिเคค เคนै, เคœिเคธเค•े เคšाเคฐों เค“เคฐ เคถเคนเคฐ, เคชเคนाเคก़ เค”เคฐ เคชเคตเคจ เคšเค•्เค•िเคฏां เคนैं। เคนाเคฒांเค•ि เคเค• เค›ोเคŸे เคธे, เคฏเคน เคšเคฎเค•ीเคฒे เคธुเคจเคนเคฐे เคฐंเค— เคฎें เค†เคถ्เคšเคฐ्เคฏเคœเคจเค• เคฆिเค–เคคा เคนै เค”เคฐ เคญเค—เคตाเคจ เคถिเคต เค•ो เคฆेเคตเคคा เค•े เคฐूเคช เคฎें เคฆेเค–เคคा เคนै। Distance between Silk Board to temple is 170KM. เคธिเคฒ्เค• เคฌोเคฐ्เคก เคธे เคฎंเคฆिเคฐ เค•े เคฌीเคš เค•ी เคฆूเคฐी 170KM เคนै।  Click here for Google Map Mavanuru Malleshwara Temple, Bijemaranahalli, Karnataka 573225 You should also Lakshmi Narasimha Nuggehalli toward Bangalore and distance is only 35KM. เค†เคชเค•ो เคฒเค•्เคท्เคฎी เคจเคฐเคธिเคฎ्เคนा เคจुเค—्เค—ेเคนเคฒ्เคฒी เคฌैंเค—เคฒोเคฐ เค•ी ...

#103 Chandra Choodeswarar Temple Hosur

'Chandra Choodeswarar' means the Eshwara who wears the Moon (Chandra) as an ornament on his crest or tuft of hair on top of the head, Shiva's consort Parvathi is worshiped here as Maragathambal. ‘Maragatham’ means green and ‘Ambal’ means mother. This is in reference to the green plants and trees (Photosynthesis), which provide sustenance to all living beings. 'เคšंเคฆ्เคฐ เคšूเคกेเคถ्เคตเคฐ' เค•ा เค…เคฐ्เคฅ เคนै เคˆเคถ्เคตเคฐ เคœो เคšंเคฆ्เคฐเคฎा (เคšंเคฆ्เคฐ) เค•ो เค…เคชเคจे เคถिเค–ा เคชเคฐ เค†เคญूเคทเคฃ เค•े เคฐूเคช เคฎें เคฏा เคธिเคฐ เค•े เคŠเคชเคฐ เคฌाเคฒों เค•े เค—ुเคš्เค›े เค•े เคฐूเคช เคฎें เคชเคนเคจเคคा เคนै, เคถिเคต เค•ी เคชเคค्เคจी เคชाเคฐ्เคตเคคी เค•ी เคฏเคนां เคฎเคฐाเค—เคฅंเคฌเคฒ เค•े เคฐूเคช เคฎें เคชूเคœा เค•ी เคœाเคคी เคนै। 'เคฎเคฐเค—เคฅเคฎ' เค•ा เค…เคฐ्เคฅ เคนै เคนเคฐा เค”เคฐ 'เค…ंเคฌเคฒ' เค•ा เค…เคฐ्เคฅ เคนै เคฎां। เคฏเคน เคนเคฐे เคชौเคงों เค”เคฐ เคชेเคก़ों (เคช्เคฐเค•ाเคถ เคธंเคถ्เคฒेเคทเคฃ) เค•े เคธंเคฆเคฐ्เคญ เคฎें เคนै, เคœो เคธเคญी เคœीเคตिเคค เคช्เคฐाเคฃिเคฏों เค•ो เคœीเคตिเค•ा เคช्เคฐเคฆाเคจ เค•เคฐเคคे เคนैं। Distance between Silk Board, Bangalore to Chandra Choodeswarar Temple Hosur is 35 KM. เคธिเคฒ्เค• เคฌोเคฐ्เคก, เคฌैंเค—เคฒोเคฐ เคธे เคšंเคฆ्เคฐ เคšूเคกेเคถ्เคตเคฐ เคฎंเคฆिเคฐ เคนोเคธुเคฐ เค•े เคฌीเคš เค•ी เคฆूเคฐी 35 KM เคนै। Click here for Google Map Sri Chandra Choodeswara Temple, Sanasandiram, Hosur, ...

#96 Hutridurga Betta _Trek_88KM

  H utridurga Fort is indeed a hidden gem near Bangalore. A trip to Hutridurga combines the pleasure of a good weekend trip from Bangalore with the thrill of trekking up the Hutridurga Uttari Betta. เคนुเคค्เคฐीเคฆुเคฐ्เค—ा เค•िเคฒा เคตाเคธ्เคคเคต เคฎें เคฌैंเค—เคฒोเคฐ เค•े เคชाเคธ เคเค• เค›िเคชा เคนुเค† เคฐเคค्เคจ เคนै। เคนुเคค्เคฐीเคฆुเคฐ्เค—ा เค•ी เคฏाเคค्เคฐा เคฌैंเค—เคฒोเคฐ เคธे เคเค• เค…เคš्เค›ी เคธเคช्เคคाเคนांเคค เคฏाเคค्เคฐा เค•े เค†เคจंเคฆ เค•ो เคนुเคค्เคฐीเคฆुเคฐ्เค—ा เค‰เคค्เคคเคฐी เคฌेเคŸ्เคŸा เคคเค• เคŸ्เคฐेเค•िंเค— เค•े เคฐोเคฎांเคš เค•े เคธाเคฅ เคœोเคก़เคคी เคนै। Distance between Silk Board, Bangalore  to Hutridurga Betta Trek Point is 88 KM. เคธिเคฒ्เค• เคฌोเคฐ्เคก, เคฌैंเค—เคฒोเคฐ เคธे เคนुเคค्เคฐीเคฆुเคฐ्เค—ा เคฌेเคŸ्เคŸा เคŸ्เคฐेเค• เคชॉเค‡ंเคŸ เค•े เคฌीเคš เค•ी เคฆूเคฐी 88 KM เคนै। Click here for Google Map Huthri Betta Hike Starting Point, Hutridurga Rd, Huthridurga(Santhepete), Karnataka 572126 You should also visit Magadi Ranganathaswamy Temple, It is 20KM toword to Bangalore. เค†เคชเค•ो เคฎเค—เคฆी เคฐंเค—เคจाเคฅเคธ्เคตाเคฎी เคฎंเคฆिเคฐ เคญी เคœाเคจा เคšाเคนिเค, เคฏเคน เคฌैंเค—เคฒोเคฐ เคธे 20 เค•िเคฎी เคฆूเคฐ เคนै। Click here for Google Map Click here for full Details and Blog Historically the Hutridurga is connected to Kempegowda who is credited as the fou...