Publicité
Publicité

Contenu connexe

Publicité

Unit1 pps

  1. BASICS OF PYTHON PROGRAMMING Prepared by Mrs. Deepa S.Rengade Asstt. Prof.
  2. python • Simple – Python is a simple and minimalistic language in nature – Reading a good python program should be like reading English – Its Pseudo-code nature allows one to concentrate on the problem rather than the language • Easy to Learn • Free & Open source – Freely distributed and Open source – Maintained by the Python community • High Level Language –memory management • Portable – *runs on anything c code will 10/18/19 Programming and problem solving 2
  3. python • Interpreted – You run the program straight from the source code. – Python program Bytecode a platforms native language – You can just copy over your code to another system and it will auto-magically work! *with python platform • Object-Oriented – Simple and additionally supports procedural programming • Extensible – easily import other code • Embeddable –easily place your code in non-python programs • Extensive libraries – (i.e. reg. expressions, doc generation, CGI, ftp, web browsers, ZIP, WAV, cryptography, etc...) (wxPython, Twisted, Python Imaging library) 10/18/19 Programming and problem solving 3
  4. python Timeline/History • Python was conceived in the late 1980s. – Guido van Rossum, Benevolent Dictator For Life – Rossum is Dutch, born in Netherlands, Christmas break bored, big fan of Monty python’s Flying Circus – Descendant of ABC, he wrote glob() func in UNIX – M.D. @ U of Amsterdam, worked for CWI, NIST, CNRI, Google – Also, helped develop the ABC programming language • In 1991 python 0.9.0 was published and reached the masses through alt.sources • In January of 1994 python 1.0 was released – Functional programming tools like lambda, map, filter, and reduce – comp.lang.python formed, greatly increasing python’s userbase 10/18/19 Programming and problem solving 4
  5. python Timeline/History • In 1995, python 1.2 was released. • By version 1.4 python had several new features – Keyword arguments (similar to those of common lisp) – Built-in support for complex numbers – Basic form of data-hiding through name mangling (easily bypassed however) • Computer Programming for Everybody (CP4E) initiative – Make programming accessible to more people, with basic “literacy” similar to those required for English and math skills for some jobs. – Project was funded by DARPA – CP4E was inactive as of 2007, not so much a concern to get employees programming “literate” 10/18/19 Programming and problem solving 5
  6. python Timeline/History • In 2000, Python 2.0 was released. – Introduced list comprehensions similar to Haskells – Introduced garbage collection • In 2001, Python 2.2 was released. – Included unification of types and classes into one hierarchy, making pythons object model purely Object-oriented – Generators were added(function-like iterator behavior) • Standards – http://www.python.org/dev/peps/pep-0008/ 10/18/19 Programming and problem solving 6
  7. Future of Python • One of the fastest growing language • Huge user base and constantly growing • Stable language that is going to stay for long • Most preferred language of companies such as Nokia, Youtube,Google,NASA for its easy syntax • High speed dynamic language • Supports for multiple programming paradigms. • Has bright future ahead of it supported by huge community of OS developers 10/18/19 Programming and problem solving 7
  8. Writing& Executing first Python Program • Download Python from www.python.org • Once installed, Python console can be accessed through – Command line and running python interpreter – GUI Software comes with python called IDLE • Writing program: – Open an Editor – write instructions – save it with extension.py – Run the interpreter with the commend python program_name.py 10/18/19 Programming and problem solving 8
  9. Literal Constants • Value of literal constant directly used in program • E.g. 7,3,9,’a’,”hello” are literal constant • They represents itself and nothing else • Its value cannot be changed • Numbers:integers,long integers,floating points,complex numbers • String:a groupof characters,immutable • Escape sequences • E.g a=rings bell, f=prints form feed character,n=newline,t=prints tab,o=octal value,x=hex value,=backslash,’=single quote,”=doublequote 10/18/19 Programming and problem solving 9
  10. Variables and identifiers • Variables are reserved memory locations that stores values. • Each variable is given appropriate name. • variables are example of identifiers • Identifiers are names given to identify something. • So it can be a variable, function, class, modules etc. • Valid identifiers: sum,_myvar,num1,var_20,a etc. • Invalid identifiers:1num,my-var,%check,basic sal . • Python is a case sensitive language. 10/18/19 Programming and problem solving 10
  11. Datatypes • Variables can hold values of different types called datatypes. • Numbers, strings, list, tuple, dictionary • Initializing values to variables e.g. a=7,code=‘a’,amt=123.45 etc. • Multiple assignment e.g. a=b=flag=0 • Assign different values to multiple variables simultaneously e.g. sum,a,b,msg=0,3,5,”rest” • Multiple statements on a single line usingsemi colon. • Boolean: datatype in python and can have one of two values-True or False. 10/18/19 Programming and problem solving 11
  12. Input Operation and Comments • Input() fuction= to take input from user • It always take input as a string • E.g. name=input(“what is your name?”) • E.g age=input(“enter your age:”) • Comments are non executable statements • Added to describe staatements of program • Characters following the# and upto end of line are part of comment • E.g. print(“hello”) #to display hello • Output: hello 10/18/19 Programming and problem solving 12
  13. Reserved words • In every programming language there are certain words which have predefined meaning called keywords or reserved words cannot be used for naming identifiers. • E.g.break,class,if,else,elif,for,from,print,retu rn • All the python keywords contain lowercase letters only. • 33 keywords in python 3.7. 10/18/19 Programming and problem solving 13
  14. Indentation • Indentation is used to define a block of code • Block of code begins with indentation and ends with the first unindented line. • Usually four white spaces are referred for indentation. • E.g no=10 If(no==10): print(“no is 10”) Output : no is 10 10/18/19 Programming and problem solving 14
  15. Operators and Expressions • Arithmetic operators: +,-,*,/,%,**,// • Assignment operators : =,+=,-=,*=,/=, %=,//=, **=,&=,|=, ^=,>>=, <<= • Comparison operators: ==,! =,>,<,>=,<= • Logical operators: and –returns true if both statements are true or- returns true if one of the statement is true not-returns false if the result is true 10/18/19 Programming and problem solving 15
  16. Operators and Expressions • Identity operators: is – returns true if both variables are the same object Is not – returns true if both variables are not the same object • Membership operators: In – returns true if a sequence with the specified value is present in the object Not in-– returns true if a sequence with the specified value is not present in the object • Bitwise operators: • & AND • | OR • ^ XOR • ~ NOT • << left shift • >> right shift 10/18/19 Programming and problem solving 16
  17. Expressions in Python • An expression is combination of value, variables and operators. • Expression appear on the right hand side of assignment operator. • E.g. add=a+b • Sub=a-b 10/18/19 Programming and problem solving 17
  18. THANK YOU 10/18/19 Programming and problem solving 18
Publicité