Python Programming Language. What have we learnt so far? Variables. What are they used for? Data types. What three data types are there? White space.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Chapter 3 – Fundamental Statements
Introduction to C Programming
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Python November 14, Unit 7. Python Hello world, in class.
Introduction to Python
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
JavaScript, Third Edition
Introduction to C Programming
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Introduction to Python
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 2 Variables.
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Python Let’s get started!.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Introduction to Python Lesson 2a Print and Types.
28 Formatted Output.
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Chapter 2 Variables.
String Methods Programming Guides.
Topics Designing a Program Input, Processing, and Output
Introduction to Python
Variables, Expressions, and IO
Introduction to Scripting
Strings Part 1 Taken from notes by Dr. Neil Moore
Java Programming: From Problem Analysis to Program Design, 4e
Python Programming Language
Unit 1: Introduction Lesson 1: PArts of a java program
Chapter 2: Basic Elements of Java
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Python Programming Language
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Python Programming Language
The Data Element.
Topics Designing a Program Input, Processing, and Output
Beginning Python Programming
Primitive Types and Expressions
The Data Element.
Chapter 2 Variables.
Python Programming Language
Lexical Elements & Operators
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Python Programming Language

What have we learnt so far? Variables. What are they used for? Data types. What three data types are there? White space. Why is this important? Statements. How do we write a statement? Comments. How do we write a comment? Arithmetic What are they? operatorsxx There is 6 in total.

Case Sensitivity You must be careful when you are typing and use the appropriate letter case for the different syntax you are using. –Variables are all in lowercase. spam = 6 –Booleans are title case.bool = True

Strings Strings are typed in between two speech marks. Below is the variable brian that has been assigned the following string. “Always look on the bright side of life”

Escape Certain character cannot be just typed into a string, they need to be escaped. For example if I’m typing in I’m I need to escape the apostrophe by using the back slash symbol. If you used double quotes you can get away without using the escape back slash symbol.

Access by Offset Each character in a string has a subscript or offset, which is a fancy way of saying it has a number attached to it. The number starts at 0 for the leftmost character and increases by one as you move character-by-character to the right. Check out the diagram in the editor!

Methods Methods are pre-built pieces of code that preform certain tasks for us. Four String Methods are : - –len()This will give us the length of the string. print len (parrot) –lower()This will convert the string to lowercase print parrot.lower() –upper()This will convert the string into upercase print parrot.upper() –str()This will make strings out of non strings print str(parrot)

Dot Notation… len(string) and str(object) Why use len(string) and str(object), but dot notation (e.g."String".upper()) for the rest. Dot notation works on string literals ("The Ministry of Silly Walks".upper()) and variables assigned to strings (ministry.upper()) because these methods are specific to strings—that is, they don't work on anything else. –best teacher = “Mr Snell is brilliant” –mr snell is brilliant”.upper() –best teacher.upper() By contrast, len() and str() can work on a whole bunch of different objects so they aren't tied to strings with dot notation –len (best teacher) MR SNELL IS BRILLIANT MR SNELL 21

Explicit String Conversion Str() turns non-strings into strings? The fancy name for that process is explicit string conversion. You're explicitly telling Python, "Hey, I know this isn't a string, but I want to turn it into one.“ –Making a number into a string can let you glue together strings and numbers (which Python normally won't allow).

String Formatting The % string formatter replaces the %s (the "s" is for "string") in our string with the variables in parentheses. The syntax went like this: –print "%s" % (string_variable) –You can have as many variables (or strings!) separated by commas between your parentheses as you like: