Python Basics. 2 Python History Late 1970s: programming language called ABC at the Centrum voor Wiskunde en Informatica in the Netherlands Audience included.

Slides:



Advertisements
Similar presentations
Lilian Blot CORE ELEMENTS PART I Python Language Autumn 2013 TPOP 1.
Advertisements

CS 100: Roadmap to Computing Fall 2014 Lecture 0.
Types and Arithmetic Operators
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Python November 14, Unit 7. Python Hello world, in class.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
A First Book of ANSI C Fourth Edition
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Introduction to Python
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 3.  Traditionally, programming languages have assigned different types of data for different types of numbers.  In many languages, there may.
Now String theory To Do: Lists This stuff hurts my brane. when you learn string theory from google images… Goal: Thinking like a machine You should now.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Chapter 2: Using Data.
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
CPS120: Introduction to Computer Science Operations Lecture 9.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Python. History of python  Python was conceived in the late 1980s and its implementation was started in December 1989 by Guido van Rossum at CWI in the.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Variables, Expressions and Statements
MM150 Unit 3 Seminar Agenda Seminar Topics Order of Operations Linear Equations in One Variable Formulas Applications of Linear Equations.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
1 Comments Allow prose or commentary to be included in program Importance Programs are read far more often than they are written Programs need to be understood.
Doing math In java.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Fundamentals of Programming I Overview of Programming
Introduction to Python
Visual Basic Variables
Data Types, Identifiers, and Expressions
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Multiple variables can be created in one declaration
Presented By S.Yamuna AP/IT
Variables, Expressions, and IO
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Variables, Data Types & Math
Chapter 2 Programming Basics.
Primitive Types and Expressions
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Introduction to Python
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Python Basics

2 Python History Late 1970s: programming language called ABC at the Centrum voor Wiskunde en Informatica in the Netherlands Audience included physicists, social scientists, and linguists 1983: Guido van Rossum joined the ABC team Late 1980s: Guido needed a language for a different project; based it on ABC, removed warts Python, after Monty Python

3 Python History Guido: Benevolent Dictator for Life (BDFL) Neat set of interviews: Search for “Guido”

4 How Python is Managed Guido collects and writes Python Enhancement Proposals (PEPs) Interested parties comment Guido makes final decisions Team of programmers (many of them volunteers!) implement the features

5 Python Types Every Python value has a type that describes what sort of value it is Built-in function type will tell you the type of an expression EnglishPython integerint “real” numberfloat picturePicture pixelPixel colourColor string of lettersstr

6 Python Numeric Types Mathematical types: int float long bool English names: integer, floating-point number, long integer, boolean int range: … float values: about …

7 Python Numeric Types long values: unlimited (any number of available locations in memory) int values that grow too large are automatically converted to long One more: bool (from “Boolean”): True, False

8 Sizes in Memory Integers have a fixed size -1 and use the same amount of memory Floating-point number have a fixed size Consequence: can’t represent every possible value Long integers can take up an arbitrarily large amount of memory

9 Python Operators Usual meaning: * + > = - ( ) New operators power: 2 ** 5 testing for equality: 3 == x remainder: 8 % 3 division: 8 / 3 assignment: num_bananas = 0

10 You’re Not My Type Operations involving different types use this hierarchy for the type of the result: float > long > int > bool 45.3 * L # result: float L - 45 # result: long 3 + True # result int (more on combining ints and bools later)

11 Mathematical Operator Precedence Operators in same box group left to right Override using parentheses **Exponentiation +x -xPositive, negative * / % // Multiplication, division, remainder, integer division + -Addition, subtraction Operator precedence, highest to lowest

12 Names Variable names, function names, and every other name you’ll see: Begin with a letter or underscore (a-z, A-Z, _) Are made up of letters, underscores, and numbers Valid: _moo_cow, cep3, I_LIKE_TRASH Invalid:

13 Naming Conventions thEre’S a GoOD rEasON wHy WorDs haVE A StaNDaRd caPITaLizAtIon sCHemE Python convention for function names and variables: pothole_case CamelCase is sometimes seen, but not for functions and variables When in doubt, use lowercase_pothole

14 Function Definition def function_name(parameters): body def keyword Zero or more, comma-separated One or more statements

15 Return Statement Form: return expression This must appear in a function body How it’s executed 1. Evaluate the expression 2. Exit the function, using the result of the expression as the value of the function call

16 Useful __builtins__ dir: produce a list of available functions and variables help: display documentation type: produce the type of an expression int, str, float, bool: type conversion min, max, abs raw_input

17 Statements You’ve seen these statements assignment: variable = value print: print expression function definition: def function(…): … function call: function(…) return: return expression for loop: for variable in list: … If statement: if expression: …

18 What’s Next Functions