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

python
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

بميـــحرلا نحنحنرلا للوللوا مــس

Fundamentals of Programming

Python

Session # 02

By: Saeed Haratian Spring 2016

slide-2
SLIDE 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

slide-3
SLIDE 3

My First Program

 Shell Mode  Python Prompt >>>  Script Mode  Print "Hello!"

slide-4
SLIDE 4

Values and Data Types

 Value  Data Type  type Function  String Quotations

 Single Quote  Double Quote  Three of a Kind

slide-5
SLIDE 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

slide-6
SLIDE 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

  • r

pass raise return try while with yield True False None

slide-7
SLIDE 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.

slide-8
SLIDE 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.

slide-9
SLIDE 9

Operators

 Addition +  Subtraction

  •  Multiplication

*  Exponentiation **  Division /  Floor Division //  Modulus %

slide-10
SLIDE 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

slide-11
SLIDE 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

slide-12
SLIDE 12

Operations on strings

 Concatenation +  Repetition *

slide-13
SLIDE 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

slide-14
SLIDE 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.

slide-15
SLIDE 15

Any Questions?