I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Adapted from John Zelle’s Book Slides
Lecture 2 Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Introduction to Python
Chapter 2 Writing Simple Programs
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
JavaScript, Third Edition
Introduction to scripting
Python Control of Flow.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CS1022 Computer Programming & Principles Lecture 1.2 A brief introduction to Python.
Python Basic Syntax. Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello,
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Computer Science 101 Introduction to Programming.
For. for loop The for loop in Python is more like a foreach iterative-type loop in a shell scripting language than a traditional for conditional loop.
If statements while loop for loop
Week 1 Algorithmization and Programming Languages.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Python Functions.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
Python Let’s get started!.
Introduction to Computing Using Python Repetition: the for loop  Execution control structures  for loop – iterating over a sequence  range() function.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
CGS 3066: Web Programming and Design Spring 2016 PHP.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
Chapter 2 Writing Simple Programs
Chapter 6 JavaScript: Introduction to Scripting
CS1022 Computer Programming & Principles
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
Variables, Expressions, and IO
Introduction to Scripting
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
PH2150 Scientific Computing Skills
Python Primer 2: Functions and Control Flow
Topics Introduction to File Input and Output
WEB PROGRAMMING JavaScript.
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Python Primer 1: Types and Operators
CISC101 Reminders All assignments are now posted.
Python Basics with Jupyter Notebook
JavaScript: Introduction to Scripting
Topics Introduction to File Input and Output
Getting Started With Coding
Presentation transcript:

I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )

C ONTINUE.. >>> for eachnum in [0,1,2]: print eachnum Eachnum contains the integer value. Python provides the range ( ) built-in function to generate such a list Example: >>> for eachnum in range (3): print eachnum >>>

C ONTINUE.. For strings, it is easy to iterate over each character: >>> foo ='abc‘ >>> for c in foo: print c a b c The range ( ) function has been often seen with len ( ) for indexing into a string. Example: >>> foo='abc' >>> for i in range (len(foo)): print foo[i],'(%d)'%i a (0) b (1) c (2) Display both elements and their corresponding index value:

B UILT - IN FUNCTIONS FunctionDescription dir([obj])Display attributes of object or the names of global variables if no parameter given. help([obj])Display object’s documentation string in a preetty- printed format or enters interactive help if no parameter given int (obj)Convert object to an integer len (obj)Return length of object open(fn,mode)Open file fn with mode ‘r’=read, ‘w’=write Range([start,]stop[,s tep]) Return a list of integers that begin at start up to but not including stop in increments of step; start defaults to 0 and step defaults to 1 raw_input(str)Wait for text input from the user; optional prompt string can be provided str(obj)Convert object to a string type (obj)Return type of object ( a type object itself)

S TATEMENTS AND SYNTAX Python statements are in general delimited by NEWLINEs- means one statement per line. Single statements can be broken up into multiple lines by using the backslash (\). Placed the (\) before a NEWLINE to continue the current statement onto the next line. >>> #check condition >>> if (weather_is_hot ==1) and \ (shark_warning_==0):

M ULTIPLE STATEMENTS GROUPS AS SUITES (:) Groups of individual statements making up a single code block are called “suites” in Python. Compound /complex statements such as if, while are those require a header line and a suite. Header line begin the statement (with the keyword and terminate with a colon (:), and are followed by one /more lines that make up the suite. A combination of a header line and a suite as a clause.

V ARIABLE ASSIGNMENT Assignment operators (=) anInt =-12 aString=‘cart’ aFloat = alist= [3.124,’ abcd’,8.82] Augmented assignment The equal sign can be combined with an arithmetic operation and the resulting value reassigned to the existing variable. Augmented assignment refer to the use of operators, which imply both an arithmetic operation as well as assignments.

C ONTINUE.. Example : +=,-=,*=, /=,%=,**=, >=,&=,^=,|= Thus, x = x+1  x+=1 Python does not support pre/post increment nor pre/post- decrement such as x++, --x Multiple assignment It is possible to assign multiple objects to multiple variables Example: >>> x=y=z=1 >>> x 1 >>> y 1 >>> z 1

C ONTINUE.. “Multuple “assignment –an alternative way to assign multiple variables. Not an official python term, used it because when assigning variables this way, the objects on both sides of the equal sign are tuples, a python standard type. Example: >>> x,y,z =1,2,'a string' >>> x 1 >>> y 2 >>> z 'a string'

C ONTINUE.. ‘multuple” assignments, not required a temporary variable to swap the values of two variables. Example: >>> #swapping variables in Python >>> x,y =1,2 >>> x 1 >>> y 2 >>> x,y=y,x >>> x 2 >>> y 1

IDENTIFIERS Are the set of valid strings that are allowed as name in a computer language. In here, there are keywords -names that form a construct of the language It is a reserved words that may not be used for any other purpose. Example : and, as, assert, break, class, continue, def,del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield, none

I DENTIFIERS - CONTINUE The rules for Python identifiers are as follow: First character must be letter or underscore (_) Any additional character can be alphanumeric or underscore Case sensitive : CASE != Case

B UILT - INS Built-ins- python additional set of identifiers, it is not a reserved words but it is not recommended to use since it is treated as “reserved for the system” It is a member of the _builtins_module