SlideShare ist ein Scribd-Unternehmen logo
1 von 136
INTRODUCTION TO PYTHON
AGENDA ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ABOUT PYTHON
PYTHON ,[object Object],[object Object],[object Object],[object Object]
COMPARISONS WITH OTHER PROGRAMMING LANGUAGES
FEATURES OF PYTHON ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
HOW TO RUN PYTHON IN ECLIPSE
WRITING FIRST PYTHON PROGRAM ,[object Object],[object Object]
[object Object],[object Object],[object Object]
[object Object]
[object Object],[object Object]
[object Object]
[object Object],[object Object],[object Object]
COPY AND PASTE INTO ECLIPSE ,[object Object]
[object Object]
[object Object],Congratulations! You have written your first program with Python.
BASIC DATA TYPES, COMMENTS AND ASSIGNMENTS
BASIC DATA TYPES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE INTO ECLIPSE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE INTO ECLIPSE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE INTO ECLIPSE ,[object Object],[object Object],[object Object],[object Object],[object Object]
COMMENTS AND WHITESPACE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object]
ASSIGNMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ACCESSING NON-EXISTENT NAMES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MULTIPLE ASSIGNMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object]
NAMING RULES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SEQUENCE TYPES: TUPLES, LISTS, AND STRINGS AND OPERATIONS ON SEQUENCE TYPES
SEQUENCE TYPES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SYNTAX ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DEFINING SEQUENCE TYPES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ACCESSING INDIVIDUAL MEMBERS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
POSITIVE AND NEGATIVE INDICES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object]
SLICING ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object]
SLICING CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object]
COPYING WHOLE SEQUENCE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
THE ‘IN’ OPERATOR ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object]
THE + OPERATOR ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
THE * OPERATOR ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
TUPLE VS LIST ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI …  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… Tuple List Immutable Mutable Fast Comparatively slow Fewer operations Lot of handy operations
OPERATIONS ON LISTS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI … ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object]
UNDERSTANDING REFERENCE SEMANTICS IN PYTHON
IMMUTABLE TYPE REFERENCES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
IMMUTABLE : EXAMPLE ,[object Object],[object Object],X reference Type Integer Data : 1 X reference Y reference Type  Integer Data: 1
CONTI… ,[object Object],X reference Y reference Type Integer Data: 1  Type Integer Data: 2
MUTABLE TYPE REFERENCES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MUTABLE : EXAMPLE ,[object Object],[object Object],li reference li reference li2 reference 1 2 3 4 1 2 3 4
CONTI… ,[object Object],li reference li 2reference 1 2 3 4 5
STRING OPERATIONS AND CONVERSIONS
STRING OPERATIONS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WHY? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
STRING CONVERSION ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DICTIONARIES
DICTIONARIES ,[object Object],[object Object],[object Object],[object Object],[object Object]
CREATING AND ACCESSING DICTIONARIES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
UPDATING ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DELETING ,[object Object],[object Object],[object Object],[object Object],[object Object]
OPERATIONS ON DICTIONARIES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BASIC OPERATIONS
ARITHMETIC OPERATOR  Operator Description Example a=5, b=3 + Addition - Adds values on either side of the operator a+b = 5+3 = 8 - Subtraction - Subtracts right hand operand from left hand operand a-b = 5-3 = 2 * Multiplication - Multiplies values on either side of the operator a*b = 5*3 = 15 / Division - Divides left hand operand by right hand operand a/b = 5/3 = 1.66666666667 % Modulus - Divides left hand operand by right hand operand and returns remainder a%b = 5%3 = 2 ** Exponent - Performs exponential (power) calculation on operators a**b = 5**3 =125 // Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. a//b = 5//3 = 1
COMPARISON OPERATORS Operator Description Example a=5, b=3 == Checks if the value of two operands are equal or not, if yes then condition becomes true. (a == b) is not true.  != Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a != b) is true.  <> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true. This is similar to != operator. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (a > b) is not true.  < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (a < b) is true.
CONTI… Operator Description Example a=5, b=3 >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true.  <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.
ASSIGNMENT OPERATORS Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand c = a + b will assigne value of a + b into c += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a
CONTI…. Operator Description Example /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a %= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a **= Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a //= Floor Division and assigns a value, Performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a
BITWISE OPERATORS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… Operator Description Example A=60(0011 1100) B=13(0000 1101) & Binary AND Operator copies a bit to the result if it exists in both operands.  (a & b) will give 12 which is 0000 1100 | Binary OR Operator copies a bit if it exists in eather operand.  (a | b) will give 61 which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both.  (a ^ b) will give 49 which is 0011 0001
CONTI…  Operator Description Example A=60(0011 1100) B=13(0000 1101) ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits.  (~a ) will give -60 which is 1100 0011 << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.  a << 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.  a >> 2 will give 15 which is 0000 1111
LOGICAL OPERATORS Operator Description Example and Called Logical AND operator. If both the operands are true then then condition becomes true. (a and b) is true. or Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (a or b) is true. not Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. not(a and b) is false.
IDENTITY OPERATORS ,[object Object],Operator Description Example is Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. x is y, here  is  results in 1 if id(x) equals id(y). is not Evaluates to false if the variables on either side of the operator point to the same object and true otherwise. x is not y, here  is not  results in 1 if id(x) is not equal to id(y).
CONTROL FLOW
CONTROL OF FLOW ,[object Object]
IF STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object]
EXAMPLE: IF STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ELSE STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
EXAMPLE: ELSE STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ELIF  STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
EXAMPLE:  ELIF  STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
NESTED  IF...ELIF...ELSE  CONSTRUCT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
EXAMPLE: NESTED  IF...ELIF...ELSE  CONSTRUCT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WHILE LOOP ,[object Object],[object Object],[object Object],[object Object],[object Object]
EXAMPLE:WHILE LOOP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONT… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FOR LOOP ,[object Object],[object Object],[object Object],[object Object],[object Object]
EXAMPLE: FOR LOOP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
LOOP CONTROL ,[object Object],[object Object]
BREAK STATEMENT ,[object Object],[object Object]
EXAMPLE: BREAK ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTINUE  STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI ... ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ELSE  STATEMENT USED WITH LOOPS ,[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PASS  STATEMENT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FUNCTIONS IN PYTHON
FUNCTIONS ,[object Object],[object Object]
DEFINING FUNCTIONS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CALLING A FUNCTION ,[object Object],[object Object],[object Object],[object Object]
COPY AND PASTE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FUNCTION ARGUMENTS ,[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI … ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CONTI… ,[object Object],[object Object],[object Object]
THANK YOU
OTHER RESOURCES ,[object Object]
TEST 1 ,[object Object],[object Object]
TEST 2 ,[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc csKALAISELVI P
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts Pavan Babu .G
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayAlexis Gallagher
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat SheetGlowTouch
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fuclimatewarrior
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way PresentationAmira ElSharkawy
 
Perl6 signatures, types and multicall
Perl6 signatures, types and multicallPerl6 signatures, types and multicall
Perl6 signatures, types and multicallSimon Proctor
 
Strings in Python
Strings in PythonStrings in Python
Strings in Pythonnitamhaske
 
Php basics
Php basicsPhp basics
Php basicshamfu
 

Was ist angesagt? (20)

Python language data types
Python language data typesPython language data types
Python language data types
 
Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc cs
 
Perl slid
Perl slidPerl slid
Perl slid
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
C# slid
C# slidC# slid
C# slid
 
C# Cheat Sheet
C# Cheat SheetC# Cheat Sheet
C# Cheat Sheet
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
 
Perl6 signatures, types and multicall
Perl6 signatures, types and multicallPerl6 signatures, types and multicall
Perl6 signatures, types and multicall
 
Perl6 signatures
Perl6 signaturesPerl6 signatures
Perl6 signatures
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Antlr V3
Antlr V3Antlr V3
Antlr V3
 
Grep Introduction
Grep IntroductionGrep Introduction
Grep Introduction
 
Python ppt
Python pptPython ppt
Python ppt
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Php basics
Php basicsPhp basics
Php basics
 

Andere mochten auch

Softhis Workflow for managing decision process
Softhis Workflow for managing decision processSofthis Workflow for managing decision process
Softhis Workflow for managing decision processMarcin Nowak
 
Managing Workflow in EnergyCAP
Managing Workflow in EnergyCAPManaging Workflow in EnergyCAP
Managing Workflow in EnergyCAPEnergyCAP, Inc.
 
Session 46 - Principles of workflow management and execution
Session 46 - Principles of workflow management and execution Session 46 - Principles of workflow management and execution
Session 46 - Principles of workflow management and execution ISSGC Summer School
 
Designing a to be process
Designing a to be processDesigning a to be process
Designing a to be processIhor Malytskyi
 
Procedures for managing workflow components, proper decision
Procedures for managing workflow components, proper decisionProcedures for managing workflow components, proper decision
Procedures for managing workflow components, proper decisioncarolyncollins
 
Organizational Function: Operations
Organizational Function: OperationsOrganizational Function: Operations
Organizational Function: OperationsNoreen Morales
 

Andere mochten auch (7)

Softhis Workflow for managing decision process
Softhis Workflow for managing decision processSofthis Workflow for managing decision process
Softhis Workflow for managing decision process
 
Managing Workflow in EnergyCAP
Managing Workflow in EnergyCAPManaging Workflow in EnergyCAP
Managing Workflow in EnergyCAP
 
Session 46 - Principles of workflow management and execution
Session 46 - Principles of workflow management and execution Session 46 - Principles of workflow management and execution
Session 46 - Principles of workflow management and execution
 
Designing a to be process
Designing a to be processDesigning a to be process
Designing a to be process
 
Procedures for managing workflow components, proper decision
Procedures for managing workflow components, proper decisionProcedures for managing workflow components, proper decision
Procedures for managing workflow components, proper decision
 
Organizational Function: Operations
Organizational Function: OperationsOrganizational Function: Operations
Organizational Function: Operations
 
Chapter 8 slides operations management
Chapter 8 slides   operations managementChapter 8 slides   operations management
Chapter 8 slides operations management
 

Ähnlich wie Introduction To Python

Ähnlich wie Introduction To Python (20)

python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Kavitha_python.ppt
Kavitha_python.pptKavitha_python.ppt
Kavitha_python.ppt
 
ENGLISH PYTHON.ppt
ENGLISH PYTHON.pptENGLISH PYTHON.ppt
ENGLISH PYTHON.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Python Basics
Python BasicsPython Basics
Python Basics
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Lenguaje Python
Lenguaje PythonLenguaje Python
Lenguaje Python
 
coolstuff.ppt
coolstuff.pptcoolstuff.ppt
coolstuff.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Introductio_to_python_progamming_ppt.ppt
Introductio_to_python_progamming_ppt.pptIntroductio_to_python_progamming_ppt.ppt
Introductio_to_python_progamming_ppt.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
manish python.pptx
manish python.pptxmanish python.pptx
manish python.pptx
 
Advanced perl finer points ,pack&amp;unpack,eval,files
Advanced perl   finer points ,pack&amp;unpack,eval,filesAdvanced perl   finer points ,pack&amp;unpack,eval,files
Advanced perl finer points ,pack&amp;unpack,eval,files
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
 
Python basics
Python basicsPython basics
Python basics
 
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfCode In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
 

Introduction To Python

  • 2.
  • 4.
  • 5. COMPARISONS WITH OTHER PROGRAMMING LANGUAGES
  • 6.
  • 7. HOW TO RUN PYTHON IN ECLIPSE
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. BASIC DATA TYPES, COMMENTS AND ASSIGNMENTS
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. SEQUENCE TYPES: TUPLES, LISTS, AND STRINGS AND OPERATIONS ON SEQUENCE TYPES
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54. CONTI… Tuple List Immutable Mutable Fast Comparatively slow Fewer operations Lot of handy operations
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68. STRING OPERATIONS AND CONVERSIONS
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 83. ARITHMETIC OPERATOR Operator Description Example a=5, b=3 + Addition - Adds values on either side of the operator a+b = 5+3 = 8 - Subtraction - Subtracts right hand operand from left hand operand a-b = 5-3 = 2 * Multiplication - Multiplies values on either side of the operator a*b = 5*3 = 15 / Division - Divides left hand operand by right hand operand a/b = 5/3 = 1.66666666667 % Modulus - Divides left hand operand by right hand operand and returns remainder a%b = 5%3 = 2 ** Exponent - Performs exponential (power) calculation on operators a**b = 5**3 =125 // Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. a//b = 5//3 = 1
  • 84. COMPARISON OPERATORS Operator Description Example a=5, b=3 == Checks if the value of two operands are equal or not, if yes then condition becomes true. (a == b) is not true. != Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a != b) is true. <> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true. This is similar to != operator. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (a > b) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (a < b) is true.
  • 85. CONTI… Operator Description Example a=5, b=3 >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.
  • 86. ASSIGNMENT OPERATORS Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand c = a + b will assigne value of a + b into c += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a
  • 87. CONTI…. Operator Description Example /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a %= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a **= Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a //= Floor Division and assigns a value, Performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a
  • 88.
  • 89. CONTI… Operator Description Example A=60(0011 1100) B=13(0000 1101) & Binary AND Operator copies a bit to the result if it exists in both operands. (a & b) will give 12 which is 0000 1100 | Binary OR Operator copies a bit if it exists in eather operand. (a | b) will give 61 which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (a ^ b) will give 49 which is 0011 0001
  • 90. CONTI… Operator Description Example A=60(0011 1100) B=13(0000 1101) ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~a ) will give -60 which is 1100 0011 << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. a << 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. a >> 2 will give 15 which is 0000 1111
  • 91. LOGICAL OPERATORS Operator Description Example and Called Logical AND operator. If both the operands are true then then condition becomes true. (a and b) is true. or Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (a or b) is true. not Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. not(a and b) is false.
  • 92.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 134.
  • 135.
  • 136.

Hinweis der Redaktion

  1. Reference Link: http://www.jvoegele.com/software/langcomp.html Object-Orientation Many languages claim to be Object-Oriented. While the exact definition of the term is highly variable depending upon who you ask, there are several qualities that most will agree an Object-Oriented language should have: Encapsulation/Information Hiding Inheritance Polymorphism/Dynamic Binding All pre-defined types are Objects All operations performed by sending messages to Objects All user-defined types are Objects A language is considered to be a &amp;quot;pure&amp;quot; Object-Oriented languages if it satisfies all of these qualities. A &amp;quot;hybrid&amp;quot; language may support some of these qualities, but not all. In particular, many languages support the first three qualities, but not the final three. So how do our languages stack up?   Java claims to be a pure Object-Oriented language, but by its inclusion of &amp;quot;basic&amp;quot; types that are not objects, it fails to meet our fourth quality. It fails also to meet quality five by implementing basic arithmetic as built-in operators, rather than messages to objects. C++ is considered to be a multi-paradigm language, of which one paradigm it supports is Object-Orientation. Thus, C++ is not (nor does it contend to be) a pure Object-Oriented language. Python is often heralded as an Object-Oriented language, but its support for Object-Orientation seems to have been tacked on. Some operations are implemented as methods, while others are implemented as global functions. Also, the need for an explicit &amp;quot;self&amp;quot; parameter for methods is awkward. Some complain about Python&apos;s lack of &amp;quot;private&amp;quot; or &amp;quot;hidden&amp;quot; attributes, which goes against the Encapsulation/Information Hiding principle, while others feel that Python&apos;s &amp;quot;privateness is by convention&amp;quot; approach offers all of the practical benefits as language-enforced encapsulation without the hassle. Visual Basic and Perl are both procedural languages that have had some Object-Oriented support added on as the languages have matured. Static vs. Dynamic Typing The debate between static and dynamic typing has raged in Object-Oriented circles for many years with no clear conclusion. Proponents of dynamic typing contend that it is more flexible and allows for increased productivity. Those who prefer static typing argue that it enforces safer, more reliable code, and increases efficiency of the resulting product. It is futile to attempt to settle this debate here except to say that a statically-typed language requires a very well-defined type system in order to remain as flexible as its dynamically-typed counterparts. Without the presence of genericity (templates, to use the C++ patois) and multiple type inheritance (not necessarily the same as multiple implementation inheritance), a static type system may severely inhibit the flexibility of a language. In addition, the presence of &amp;quot;casts&amp;quot; in a language can undermine the ability of the compiler to enforce type constraints. A dynamic type system doesn&apos;t require variables to be declared as a specific type. Any variable can contain any value or object. Smalltalk and Ruby are two pure Object-Oriented languages that use dynamic typing. In many cases this can make the software more flexible and amenable to change. However, care must be taken that variables hold the expected kind of object. Typically, if a variable contains an object of a different type than a user of the object expects, some sort of &amp;quot;message not understood&amp;quot; error is raised at run-time. Users of dynamically-typed languages claim that this type of error is infrequent in practice. Statically-typed languages require that all variables are declared with a specific type. The compiler will then ensure that at any given time the variable contains only an object compatible with that type. (We say &amp;quot;compatible with that type&amp;quot; rather than &amp;quot;exactly that type&amp;quot; since the inheritance relationship enables subtyping, in which a class that inherits from another class is said to have an IS-A relationship with the class from which it inherits, meaning that instances of the inheriting class can be considered to be of a compatible type with instances of the inherited class.) By enforcing the type constraint on objects contained or referred to by the variable, the compiler can ensure a &amp;quot;message not understood&amp;quot; error can never occur at run-time. On the other hand, a static type system can hinder evolution of software in some circumstances. For example, if a method takes an object as a parameter, changing the type of the object requires changing the signature of the method so that it is compatible with the new type of the object being passed. If this same object is passed to many such methods, all of them must be updated accordingly, which could potentially be an arduous task. One must remember, though, that this ripple effect could occur even a dynamically-typed language. If the type of the object is not what it was originally expected to be, it may not understand the messages being sent to it. Perhaps even worse is that it could understand the message but interpret it in a way not compatible with the semantics of the calling method. A statically-typed language can flag these errors at compilation-time, pointing out the precise locations of potential errors. A user of a dynamically-typed language must rely on extensive testing to ensure that all improper uses of the object are tracked down. Eiffel is a statically-typed language that manages to remain nearly as flexible as its dynamic counterparts. Eiffel&apos;s generic classes and unprecedentedly flexible inheritance model allow it to achieve the safety and reliability of a static type system while still remaining nearly as flexible as a dynamic type system, all without requiring (nor allowing) the use of type casts. C++ also offers generic classes (known as &amp;quot;templates&amp;quot; in the C++ parlance), as well as multiple inheritance. Unfortunately, the presence of type casts and implicit type conversions can sometimes undermine the work of the compiler by allowing type errors to go undetected until run-time. Java is seriously hindered by a lack of generic classes. This is alleviated to a degree by Java&apos;s singly-rooted type hierarchy (i.e. every class descends directly or indirectly from from the class Object), but this scheme leaves much to be desired in terms of type-safety. Forthcoming versions of Java will address this shortcoming when generic classes are introduced in Java 1.5 or later. Java also allows type casting, but some rudimentary type checks can be made by the compiler, making casts in Java somewhat safer than in C++ and other languages. Higher Order Functions &amp; Lexical Closures Higher order functions are, in the simplest sense, functions that can be treated as if they were data objects. In other words, they can be bound to variables (including the ability to be stored in collections), they can be passed to other functions as parameters, and they can be returned as the result of other functions. Due to this ability, higher order functions may be viewed as a form of deferred execution, wherein a function may be defined in one context, passed to another context, and then later invoked by the second context. This is different from standard functions in that higher order functions represent anonymous lambda functions, so that the invoking context need not know the name of the function being invoked. Lexical closures (also known as static closures, or simply closures) take this one step further by bundling up the lexical (static) scope surrounding the function with the function itself, so that the function carries its surrounding environment around with it wherever it may be used. This means that the closure can access local variables or parameters, or attributes of the object in which it is defined, and will continue to have access to them even if it is passed to another module outside of its scope. Among the languages we&apos;re considering, Smalltalk and Ruby have supported both higher order functions and lexical closures from the beginning in the form of blocks. A block is an anonymous function that may be treated as any other data object, and is also a lexical closure. Eiffel has recently added support for higher order functions using the &amp;quot;agent&amp;quot; mechanism. The inline variant of Eiffel agents forms a lexical closure. Python, which has long supported higher order functions in the form of lambda expressions, has recently added support for closures using its improved support for nested static scopes. While neither Java nor C++ support higher order functions directly, both provide mechanisms for mimicking their behavior. Java&apos;s anonymous classes allow a function to be bundled with an object that can be treated much as a higher order function can. It can be bound to variables, passed to other functions as an argument, and can be returned as the result of a function. However, the function itself is named and thus cannot be treated in a generic fashion as true higher order functions can. C++ similarly provides partial support for higher order functions using function objects (or &amp;quot;functors&amp;quot;), and add the further benefit that the function call operator may be overloaded so that functors may be treated generically. Neither C++ nor Java, however, provide any support for lexical closures. Visual Basic provides no support for either higher order functions or lexical closures, nor is there any apparent mechanism for providing similar behavior. Language Integration For various reasons, including integration with existing systems, the need to interact with low level modules, or for sheer speed, it is important for a high level language (particularly interpreted languages) to be able to integrate seamlessly with other languages. Nearly every language to come along since C was first introduced provides such integration with C. This allows high level languages to remain free of the low level constructs that make C great for systems programming, but add much complexity. All of the languages under discussion integrate tightly with C, except for Visual Basic, which can only do so through DCOM. Eiffel and Ruby provide particularly easy-to-use interfaces to C as well as callbacks to the language runtime. Python, Perl, Java, and Smalltalk provide similar interfaces, though they aren&apos;t quite as easy to use. C++, naturally, integrates quite transparently with C. Access Control Access control refers to the ability for a modules implementation to remain hidden behind its public interface. Access control is closely related to the encapsulation/information hiding principle of object-oriented languages. For example, a class Person may have methods such as name and email, that return the person&apos;s name and e-mail address respectively. How these methods work is an implementation detail that should not be available to users of the Person class. These methods may, for example, connect to a database to retrieve the values. The database connection code that is used to do this is not relevant to client code and should not be exposed. Language-enforced access control allows us to enforce this. Most object-oriented languages provide at least two levels of access control: public and protected. Protected features are not available outside of the class in which they are contained, except for subclasses. This is the scheme supported by Smalltalk, in which all methods are public and all attributes are protected. There are no protected methods in Smalltalk, so Smalltalk programmers resort to the convention of placing methods that should be protected into a &amp;quot;private protocol&amp;quot; of the class. although since there is no inheritance in Visual Basic, protected features are effectively private to the class in which they are declared. Some languages, notably Java and C++, provide a third level of access control known as &amp;quot;private&amp;quot;. Private features are not available outside of the class in which they are declared, even for subclasses. Note, however, that this means that objects of a particular class can access the private features of other objects of that same class. Ruby also provides these three levels of access control, but they work slightly differently. Private in Ruby means that the feature cannot be accessed through a receiver, meaning that the feature will be available to subclasses, but not other instances of the same class. Java provides a fourth level of, known as &amp;quot;package private&amp;quot; access control which allows other classes in the same package to access such features. Eiffel provides the most powerful and flexible access control scheme of any of these languages with what is known as &amp;quot;selective export&amp;quot;. All features of an Eiffel class are by default public. However, any feature in an Eiffel class may specify an export clause which lists explicitly what other classes may access that feature. The special class NONE may be used to indicate that no other class may access that feature. This includes attributes, but even public attributes are read only so an attribute can never be written to directly in Eiffel. In order to better support the Open-Closed principle, all features of a class are always available to subclasses in Eiffel, so there is no notion of private as there is in Java and C++. Python, curiously, does not provide any enforced access control. Instead, it provides a mechanism of name mangling: any feature that begins with underscores will have its name mangled by the Python interpreter. Although this does not prevent client code from using such features, it is a clear indicator that the feature is not intended for use outside the class and convention dictates that these features are &amp;quot;use at your own risk&amp;quot;.
  2. Simple Python is a simple and minimalistic language. Reading a good Python program feels almost like reading English, although very strict English! This pseudo-code nature of Python is one of its greatest strengths. It allows you to concentrate on the solution to the problem rather than the language itself. Easy to Learn As you will see, Python is extremely easy to get started with. Python has an extraordinarily simple syntax, as already mentioned. Free and Open Source Python is an example of a FLOSS (Free/Libré and Open Source Software). In simple terms, you can freely distribute copies of this software, read it&apos;s source code, make changes to it, use pieces of it in new free programs, and that you know you can do these things. FLOSS is based on the concept of a community which shares knowledge. This is one of the reasons why Python is so good - it has been created and is constantly improved by a community who just want to see a better Python. High-level Language When you write programs in Python, you never need to bother about the low-level details such as managing the memory used by your program, etc. Portable Due to its open-source nature, Python has been ported (i.e. changed to make it work on) to many platforms. All your Python programs can work on any of these platforms without requiring any changes at all if you are careful enough to avoid any system-dependent features. You can use Python on Linux, Windows, FreeBSD, Macintosh, Solaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, z/OS, Palm OS, QNX, VMS, Psion, Acorn RISC OS, VxWorks, PlayStation, Sharp Zaurus, Windows CE and even PocketPC ! Interpreted This requires a bit of explanation. A program written in a compiled language like C or C++ is converted from the source language i.e. C or C++ into a language that is spoken by your computer (binary code i.e. 0s and 1s) using a compiler with various flags and options. When you run the program, the linker/loader software copies the program from hard disk to memory and starts running it. Python, on the other hand, does not need compilation to binary. You just run the program directly from the source code. Internally, Python converts the source code into an intermediate form called bytecodes and then translates this into the native language of your computer and then runs it. All this, actually, makes using Python much easier since you don&apos;t have to worry about compiling the program, making sure that the proper libraries are linked and loaded, etc, etc. This also makes your Python programs much more portable, since you can just copy your Python program onto another computer and it just works! Object Oriented Python supports procedure-oriented programming as well as object-oriented programming. In procedure-oriented languages, the program is built around procedures or functions which are nothing but reusable pieces of programs. In object-oriented languages, the program is built around objects which combine data and functionality. Python has a very powerful but simplistic way of doing OOP, especially when compared to big languages like C++ or Java. Extensible If you need a critical piece of code to run very fast or want to have some piece of algorithm not to be open, you can code that part of your program in C or C++ and then use them from your Python program. Embeddable You can embed Python within your C/C++ programs to give &apos;scripting&apos; capabilities for your program&apos;s users. Extensive Libraries The Python Standard Library is huge indeed. It can help you do various things involving regular expressions, documentation generation, unit testing, threading, databases, web browsers, CGI, ftp, email, XML, XML-RPC, HTML, WAV files, cryptography, GUI (graphical user interfaces), Tk, and other system-dependent stuff. Remember, all this is always available wherever Python is installed. This is called the &apos;Batteries Included&apos; philosophy of Python. Besides, the standard library, there are various other high-quality libraries such as wxPython, Twisted, Python Imaging Library and many more.
  3. Numeric value = be it decimal or integer
  4. Python allows us to use single, double and also triple quotes. All Python asks is that you close the value with the same kind that you opened it (otherwise, Python will not know where you mean the quotes to be part of the value or to signify the end of the string). If you begin a value with double quotes, you must end it with double quotes.
  5. tu = (23, ‘abc’ , 4.56, (2,3), ‘def’ ) Here (2,3) is collection type