Mr. Crone.  Use print() to print to the terminal window  print() is equivalent to println() in Java Example) print(“Hello1”) print(“Hello2”) # Prints:

Slides:



Advertisements
Similar presentations
Escape Sequences \n newline \t tab \b backspace \r carriage return
Advertisements

This is Java Jeopardy.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
Introduction to Python
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
String Escape Sequences
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Introduction to Computing Using Python Python  Python is an interactive language.  Java or C++: compile, run  Also, a main function or method  Python:
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
2440: 211 Interactive Web Programming Expressions & Operators.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Input, Output, and Processing
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Python The tutorial
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
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.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Introduction to Strings CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
A Tutorial on the Python Programming Language. Overview Running Python and Output Data Types Input and File I/O Control Flow Functions.
Variables, Types, Expressions Intro2CS – week 1b 1.
Chapter 2 print / println String Literals Escape Characters Variables / data types.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Introduction to Python Developed by Dutch programmer Guido van Rossum Named after Monty Python Open source development project Simple, readable language.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
String and Lists Dr. José M. Reyes Álamo.
G. Pullaiah College of Engineering and Technology
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
CSc 120 Introduction to Computer Programing II Adapted from slides by
String class.
Ruby and other languages….
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Introduction to Scripting
Introduction to Strings
Introduction to C++ Programming
CHAPTER THREE Sequences.
An overview of Java, Data types and variables
String and Lists Dr. José M. Reyes Álamo.
Reading Input from the Keyboard
Recap Week 2 and 3.
Topics Designing a Program Input, Processing, and Output
CHAPTER 3: String And Numeric Data In Python
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 Variables.
More Basics of Python Common types of data we will work with
Presentation transcript:

Mr. Crone

 Use print() to print to the terminal window  print() is equivalent to println() in Java Example) print(“Hello1”) print(“Hello2”) # Prints: #Hello1 #Hello2

 Use a comma to print strings and variables Example) var = 5 print(“Var 1 = “, var)

 Single line comments begin with: # Example) # This is a comment  Multi-line comments begin and end with: ‘’’ Example) ‘’’ Comment line 1 comment line 2’’’

 Same as Java: *, +, -, %  Use parentheses for grouping  / always returns a floating point number  // - floor division – returns integer result of division statement Example) print(5/2) # Prints 2.5 print(5//2) # Prints 2

 Use, **, to calculate powers Example) print(4**2) #Prints 4 squared, or 16

 Can be declared using single or double quotes Example) x = ‘I am a String’ y = “I am a Sting” # x and y are both Strings

 \n and \t represent newline and tab respectively  \ is the escape character and can be used to “escape” quotes

 Use ‘’’ or “”” to create multiline string literals Example) print('''line1 line2 line3 line4''') #Prints: line1 line2 line3 line4

 Use backslash to prevent automatic newlines Example) print('''line1\ line2\ line3\ line4''') #Prints: line1line2line3line4

 Strings can be concatenated with: + Example) x = “yes” y = “no” z = x + y #yesno  Strings can be repeated with: * z = x * 3 #yesyesyes

 Two or more string literals next to each other are automatically concatenated Example) print(‘house’ ‘mouse’) #housemouse

 Individual characters of Strings can accessed by specifying a character index Example) x = 'hello' print(x[0]) #Prints h  Negative indices start at the end of the string x = 'cat' print(x[-1]) #Prints t

 Substrings can be accessed with the syntax below Example) x = "Splended" print(x[1:4]) # Prints: ple #1 is included, 4 is not included

 Strings are immutable – cannot be changed x = “Dog” x[0] = “F” # ERROR

 Use the length function to return the length of a string len(x) Example) x = “Cat” print(len(x)) #Prints: 3

 Lists are used to group several values together  Use square brackets to designate a list x = [1, 3, 5, 7] Example) x =[1, 3, 5, 7, "String"] print(x[4]) # Prints: String

 Use the length function to print the size of a list  x =[1, 3, 5, 7, "String"]  print(len(x)) # Prints: 5

 Negative indices are allowed x =[1, 3, 5, 7, "String"] print(x[-2]) #Prints: 7  Slicing uses the same syntax as Strings x =[1, 3, 5, 7, "String"] print(x[0:2]) #Prints: [1,3]

 Lists can be combined with: + Example) x = [1, 3, 5] y = [2, 4] z = x + y print(z) #[1, 3, 5, 2, 4]

 Lists are mutable and can be modified  Lists can grow in size with the append method Example) x = [1, 3, 5] x.append(7); print(x) # Prints: [1, 3, 5, 7]

 Same as C++ and Java  >  <  >=  <=  ==  !=

Syntax: while condition : body statements Example) x = 1 while x < 5: print(x) x+=1

Syntax if condition : body statements elif condition : body statements else: body statements

 Syntax var = input(“Prompt”) Example) x = input(“Enter a number: “)

 Variables can be cast to specific types Example) x = float(input(“Enter a number”)) #Ensures that the variable above can be # used in arithmetic expressions int(5.5) #returns 5

 Use random.random() to generate random numbers in the range [0,1)  Must include, import random, at top of module Example) x = int(random.random() * 10) #Generates random number 0-9

 Max and Min are built into Python and can be used without an import statement Example) print(max(3, 4)) #Prints 4