Basics	
  of	
  Python	
  Programming	
  
Rohan	
  Koodli	
  
Hello	
  World	
  
l  First	
  program	
  in	
  Python	
  
Variables	
  
l  Variables	
  can	
  change	
  
l  Can	
  be	
  number,	
  string,	
  list	
  
l  Individual	
  variables	
  can	
  change	
  types(unlike	
  other	
  languages)	
  
Comparisons	
  
l  The	
  “=“	
  assigns	
  variable	
  names	
  
l  The	
  “==“	
  checks	
  for	
  equality	
  
l  !=,	
  >,	
  <,	
  >=,	
  <=	
  
If/Else	
  Statements	
  
l  Controls	
  flow	
  of	
  the	
  program	
  
l  If,	
  Elif	
  (else	
  if),	
  else	
  
Loops	
  
l  While	
  Loops	
  
l  Executes	
  a	
  task	
  while	
  something	
  is	
  true	
  
l  For	
  Loops	
  
l  Iterates	
  over	
  elements	
  
Prints	
  ‘hi’	
  forever	
  (1	
  is	
  
always	
  less	
  than	
  5	
  
Lists	
  
l  Sequence	
  of	
  data	
  
l  You	
  can	
  iterate	
  over	
  a	
  list	
  
l  Indexing(indexes	
  start	
  at	
  zero)	
  
Tuples	
  
l  Similar	
  to	
  lists	
  
l  Cannot	
  change	
  tuples	
  
Strings	
  
l  Can	
  iterate	
  over	
  strings	
  
l  Many	
  funcYons	
  for	
  strings	
  
FuncYons	
  
l  Use	
  “def”	
  
l  One	
  funcYon	
  can	
  be	
  used	
  mulYple	
  Ymes	
  
l  Lambdas	
  
Import	
  
l  Used	
  to	
  load	
  up	
  a	
  library	
  
Classes	
  
l  Contains	
  data	
  
l  Contains	
  instance	
  variables	
  
l  ‘self’	
  allows	
  you	
  to	
  modify	
  variable	
  later	
  on	
  
l  ‘__init__’	
  called	
  when	
  you	
  use	
  make	
  an	
  instance	
  of	
  the	
  class	
  

Python basics

  • 1.
    Basics  of  Python  Programming   Rohan  Koodli  
  • 2.
    Hello  World   l First  program  in  Python  
  • 3.
    Variables   l  Variables  can  change   l  Can  be  number,  string,  list   l  Individual  variables  can  change  types(unlike  other  languages)  
  • 4.
    Comparisons   l  The  “=“  assigns  variable  names   l  The  “==“  checks  for  equality   l  !=,  >,  <,  >=,  <=  
  • 5.
    If/Else  Statements   l Controls  flow  of  the  program   l  If,  Elif  (else  if),  else  
  • 6.
    Loops   l  While  Loops   l  Executes  a  task  while  something  is  true   l  For  Loops   l  Iterates  over  elements   Prints  ‘hi’  forever  (1  is   always  less  than  5  
  • 7.
    Lists   l  Sequence  of  data   l  You  can  iterate  over  a  list   l  Indexing(indexes  start  at  zero)  
  • 8.
    Tuples   l  Similar  to  lists   l  Cannot  change  tuples  
  • 9.
    Strings   l  Can  iterate  over  strings   l  Many  funcYons  for  strings  
  • 10.
    FuncYons   l  Use  “def”   l  One  funcYon  can  be  used  mulYple  Ymes   l  Lambdas  
  • 11.
    Import   l  Used  to  load  up  a  library  
  • 12.
    Classes   l  Contains  data   l  Contains  instance  variables   l  ‘self’  allows  you  to  modify  variable  later  on   l  ‘__init__’  called  when  you  use  make  an  instance  of  the  class