Outline Basic concepts of Python language



Similar documents
Introduction to Python

Variables, Constants, and Data Types

CS 1133, LAB 2: FUNCTIONS AND TESTING

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Chapter 2: Elements of Java

Python Programming: An Introduction to Computer Science

Introduction to Python

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

ESPResSo Summer School 2012

Introduction to Visual C++.NET Programming. Using.NET Environment

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Pemrograman Dasar. Basic Elements Of Java

CS 106 Introduction to Computer Science I

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Python Loops and String Manipulation

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

C++ Language Tutorial

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Informatica e Sistemi in Tempo Reale

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Tokens and Python s Lexical Structure

Chapter 2 Introduction to Java programming

Hands-On Python A Tutorial Introduction for Beginners Python 3.1 Version

Python Evaluation Rules

Introduction to Java

Object Oriented Software Design

Introduction to Java. CS 3: Computer Programming in Java

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Exercise 4 Learning Python language fundamentals

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn Claus Führer Simulation Tools Automn / 65

Python Lists and Loops

Chapter One Introduction to Programming

Moving from CS 61A Scheme to CS 61B Java

Object Oriented Software Design

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Computational Mathematics with Python

Computational Mathematics with Python

CS106A, Stanford Handout #38. Strings and Chars

An introduction to Python for absolute beginners

[1] Learned how to set up our computer for scripting with python et al. [3] Solved a simple data logistics problem using natural language/pseudocode.

AP Computer Science Static Methods, Strings, User Input

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Sources: On the Web: Slides will be available on:

Objects and classes. Objects and classes. Jarkko Toivonen (CS Department) Programming in Python 1

Chapter 13 Storage classes

Chapter 15 Functional Programming Languages

LEARNING TO PROGRAM WITH PYTHON. Richard L. Halterman

Member Functions of the istream Class

Object-Oriented Programming in Java

Programming Languages CIS 443

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

The Cool Reference Manual

Using SQL Queries in Crystal Reports

Java Basics: Data Types, Variables, and Loops

Introduction to Python

Computational Mathematics with Python

Assignment 3 Version 2.0 Reactive NoSQL Due April 13

Apache Cassandra Query Language (CQL)

Repetition Using the End of File Condition

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

Oracle SQL. Course Summary. Duration. Objectives

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

HTML Web Page That Shows Its Own Source Code

AP Computer Science Java Subset

Computer Programming Tutorial

Programming and Reasoning with Side-Effects in IDRIS

13 File Output and Input

Welcome to Introduction to programming in Python

C# programming. Introduction. By Per Laursen

Ecma/TC39/2013/NN. 4 th Draft ECMA-XXX. 1 st Edition / July The JSON Data Interchange Format. Reference number ECMA-123:2009

Principles of Database Management Systems. Overview. Principles of Data Layout. Topic for today. "Executive Summary": here.

Udacity cs101: Building a Search Engine. Extracting a Link

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Writing Simple Programs

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++

Programming Project 1: Lexical Analyzer (Scanner)

Anatomy of Programming Languages. William R. Cook

Chapter 5 Names, Bindings, Type Checking, and Scopes

Oracle Database 12c: Introduction to SQL Ed 1.1

Some Scanner Class Methods

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

HA Proxy DNS Configuration Mode Commands

Example of a Java program

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Hands-On UNIX Exercise:

Transcription:

Data structures: lists, tuples, sets, dictionaries

Basic data types Examples: int: 12, 0, -2 float: 1.02, -2.4e2, 1.5e-3 complex: 3+4j bool: True, False string: "Test string"

Conversion between types int(-2.8) -2 float(2) 2.0 int( 123 ) 123 bool(-2) True, bool(0) False str(234) 234

Strings 1 A sequence of characters delimitted between single ( ) or double ( ) quotes This optionality is useful if a string needs to contain a quotation mark. You can also achieve this by escaping the quotation mark: \" or \ Can also contain escape sequences like \n for newline and \t for tabulator. See page 41 of the course page for all escape sequences. Strings can be concatenated with the + operator: "compu" + "ter" results a new string computer.

Strings 2 If you want a string to contain several lines of text, use triple quoted strings: First line second line

Expressions 1 An expression is a piece of Python code that results in a value It consists of values combined together with operators Values can be literals or variables Operators include arithmetic operators, comparison operators, function calls, indexing, attribute references, among others. Examples of expressions: 1+2 c > 0 and c!= 1 7/(2+0.1) (1,2,3) a a < 5 cos(0) obj.attr mylist[1] (-1)**2 == 1

Expressions 2 Usually expressions don t do anything beyond resulting a value, but sometimes an epression, typically a function call, can have side-effects Side-effects that functions may have, should be well documented. Otherwise unexpected behaviour and confusion can occur, and the reason for this is hard to pinpoint For example, the function (method) writeline has the side-effect of changing the contents of a file. Programming without any side-effects is called functional programming Python is not a functional programming language, it is an imperative language

Statements 1 Statements are commands that have some effect Simplest example of statements is just an expression: Usually these are function calls Are also used in interactive use: the interpreter prints the computed value of an expression The print statement prints the values of expressions: print expr1, expr2,... Another simple statement is an assignment: variable name = expression

Variables Variable is a name that refers to a value or an object With the assignment operator, you can bind a variable name to a value, and rebind it later to another value In Python types are not attached to variable names; types are attached to objects/values in the memory of the computer This is runtime/dynamic typing Therefore a variable name var can at one time point to an string and a few seconds later point to a complex number This can make your program a bit confusing: try to avoid it

Bindings and type checking in C and Python C static typing memory Python dynamic typing memory int variable_name type variable_name str