Python. Quick Points About Python Python is an interpreted language –Like Perl you don’t have to compile it –It has a command line interpreter if you.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is.
Μαθαίνοντας Python [Κ4] ‘Guess the Number’
An Introduction to Python – Part II Dr. Nancy Warter-Perez.
Title An Introduction to Python. What is Python exactly? Python is a modern rapid development language. Code is very clean and easy to read. Emphasizes.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
An Introduction to Python Dr. Nancy Warter-Perez April 15, 2004.
An Introduction to Python and Its Use in Bioinformatics Dr. Nancy Warter-Perez.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Java Basics Kris Secor Mobile Application Development.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.
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,
Introduction to Programming Workshop 2 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Python Basics Tom LeFebvre. Sept , 2002Python Basics2 Python Language Very High-Level Language Scripting Language (no compiling) Simple syntax Easy.
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.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
Computer Programming Your First Java Program: HelloWorld.java.
Agenda Introduction Computer Programs Python Variables Assignment
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
Whatcha doin'? Aims: To start using Python. To understand loops.
Python Variable Types.
Topic Pre-processor cout To output a message.
EECS 183 Discussion #9: It’s time to “Git” Python! November 22nd, 2016
When to use Tuples instead of Lists
An Introduction to Python and Its Use in Bioinformatics
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Pamela Moore & Zenia Bahorski
CS230 Tutorial Week 3.
Getting Started with C.
Computer Programming Methodology Introduction to Java
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.
Shell scripts on Pegasus 2
Intro to Java.
Thinking about programming
Statements, Comments & Simple Arithmetic
Introduction to Python
Introduction to CS Your First C Programs
2.1 Parts of a C++ Program.
An Introduction to Python
Java Tutotrial for [NLP-AI] 2
Introduction to C Topics Compilation Using the gcc Compiler
Statements and expressions - java
Arrays ICS2O.
Introduction to C Topics Compilation Using the gcc Compiler
CHAPTER 4: Lists, Tuples and Dictionaries
Thinking about programming
Thinking about programming
Python Review
Comparing Python and Java
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Chapter 2 part #1 C++ Program Structure
Dictionary.
Python fundamental.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Python

Quick Points About Python Python is an interpreted language –Like Perl you don’t have to compile it –It has a command line interpreter if you want to try things out Python is free –You can download it from: –

No semicolons A new line terminates a statement –No semicolons are needed If you need to continue a long line, you can use a slash \ character at the end print "Hello World" a = "Now is the time for all good men" + \ "to come to the aid of their country" print a

Comments Comments are denoted with a # Comments can also be written as strings that are not used # this is a comment """ Now is the time to comment this line is a comment too bla bla bla """

Indention Matters A block of code has all the lines indented the same number of spaces –That is the only way a block is indicated –No curly braces {} –A block of code ends when the indent level reverts to the level of an outer block

Example Block of Code i = 0 while i < 5 : print i i = i + 1 print "done"

Assigning to Variables Variables can hold strings or numbers i = 5 print i i = "hello" print i Mulitple variables can be assigned at once two, three = 2,3 x, y = y, x # really swaps

Python does NOT convert between strings and numbers automatically You can use the built-in int() function a = 1 b = "2" c = a + int(b)

Strings You can use single or double quotes State = "Maryland" State = 'TN‘ Sentence = """ This is a long sentence that finishes on the another line """

Indexing Strings >>> name1 = "Tom" >>> name2 = "Jones" >>> newname = name1[0] + name2[:3] + "123" >>> print newname TJon123 >>> print newname[-3] 1 >>> print newname[:3] TJo

Lists and Tuples mylist = [ “hello”, 7, “green” ] mytuple = ( “hello”, 7, (“red”, 31) ) firstelement = mylist[0] lastelement = mylist[-1] subtuple = mytuple[1:3] mylist[1] = “newlistvalue” mylist.append( 9 ) mylist.extend( [“new”, “entries”, 50] ) print “List has“, len(mylist), “elements” del mylist[2] del mylist[0:1]

Dictionaries mydict[0] = “first” mydict[1] = “Second” mydict[“zero”] = “First” mydict[“one”] = “Second”

If c == 12: c = 1 for element in mylist: print element