python
play

Python Session # 02 By: Saeed Haratian Spring 2016 Outlines My - PowerPoint PPT Presentation

Fundamentals of Programming Python Session # 02 By: Saeed Haratian Spring 2016 Outlines My First Program Comments Values and Data Types Variables and Keywords


  1. بميـــحرلا نحنحنرلا للوللوا مــس Fundamentals of Programming Python Session # 02 By: Saeed Haratian Spring 2016

  2. Outlines  My First Program  Comments  Values and Data Types  Variables and Keywords  Statements  Expressions  Operators  Order of operations  Type Conversions  Operations on strings  Input  Composition

  3. My First Program  Shell Mode  Python Prompt >>>  Script Mode  Print "Hello!"

  4. Values and Data Types  Value  Data Type  type Function  String Quotations  Single Quote  Double Quote  Three of a Kind

  5. Variables  A Variable is a Name that refers to a Value .  Assignment token, =  Not Confused with equal ==  Variables are variable.  Variable Names  can be arbitrarily long  can contain letters, digits and underscore ( _ )  have to begin with a letter or an underscore  are case sensitive  have not to be Keyword

  6. Keywords and as assert break class continue def del elif else except exec finally for from global if import in is lambda nonlocal not or pass raise return try while with yield True False None

  7. Statement  A Statement is an instruction that the Python interpreter can execute.  We have only seen the assignment statement so far.  Some other kinds of statements that we’ll see shortly are while statements, for statements, if statements, and import statements. (There are other kinds too!)  When you type a statement on the command line, Python executes it.  Statements don’t produce any result.

  8. Expression  An expression is a combination of values , variables , operators , and calls to functions.  If you type an expression at the Python prompt, the interpreter evaluates it and displays the result.  The evaluation of an expression produces a value.

  9. Operators  Addition +  Subtraction -  Multiplication *  Exponentiation **  Division /  Floor Division //  Modulus %

  10. Order of operations  Parentheses highest  Exponentiation  Multiplication, Division and Modulus  Addition and Subtraction lowest Operators with the same precedence are evaluated from left-to-right except Exponentiation

  11. Type Conversion  The int function can take a floating point number or a string, and turn it into an int.  The float function can turn an integer, a float, or a syntactically legal string into a float.  The str function turns its argument into a string

  12. Operations on strings  Concatenation +  Repetition *

  13. Input  input is a built-in function for getting input from the user  input always returns a string  It would be your job, to convert that string into an int or a float, using the converter functions

  14. Composition  So far, we have looked at the elements of a program — variables, expressions, statements, and function calls — in isolation  Without talking about how to combine them.  One of the most useful features of programming languages is their ability to take small building blocks and compose them into larger chunks.

  15. Any Questions?

Recommend


More recommend