More Basics of Python Common types of data we will work with

Slides:



Advertisements
Similar presentations
Intro to Python Welcome to the Wonderful world of GIS programing!
Advertisements

Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Introduction to Python
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Python Types Python values are of various “types” Ints, Floats, Strings, Characters, and more Two representations of numbers 1 vs 1.0.
Numeric Types, Expressions, and Output ROBERT REAVES.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
COMPSCI 101 Principles of Programming Lecture 4 –The type() function, the string type, the len() function, string slices.
Strings CS303E: Elements of Computers and Programming.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Announcements Additional office hours tomorrow: 3-6pm in HAAS 142 Midterm Bring a #2 pencil (test given via scantron sheet) Photo ID No Labs or Recitation.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
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.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Simple Python Data Victor Norman CS104 Calvin College.
ICAPRG301A Week 2 Strings and things Charles Babbage Developed the design for the first computer which he called a difference engine, though.
Xin Liu Feb 4, * Use midterm questions for previous 231/217 midterms for practices * ams
Please log on The. AN INTRODUCTION TO ‘Python is a high-level, general purpose programming language’ Python is one of the many programming languages.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Last Week Modules Save functions to a file, e.g., filename.py The file filename.py is a module We can use the functions in filename.py by importing it.
Lecture 09 – Classes.  At the end of this lecture, students should be able to:  Define a new class  Store state information about instances of the.
Variables, Types, Expressions Intro2CS – week 1b 1.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Data Manipulation Variables, Data Types & Math. Aug Variables A variable is a name (identifier) that points to a value. They are useful to store.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
Mr. Crone.  Use print() to print to the terminal window  print() is equivalent to println() in Java Example) print(“Hello1”) print(“Hello2”) # Prints:
Input, Output and Variables GCSE Computer Science – Python.
DAY 2. GETTING FAMILIAR WITH NGS SANGREA SHIM. INDEX  Day 2  Get familiar with NGS  Understanding of NGS raw read file  Quality issue  Alignment/Mapping.
Introduction to Programming
G. Pullaiah College of Engineering and Technology
Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Lesson 1 - Sequencing.
COMPSCI 107 Computer Science Fundamentals
Example: Vehicles What attributes do objects of Sedan have?
Introduction to Python
Data Types and Conversions, Input from the Keyboard
Presented By S.Yamuna AP/IT
Variables, Expressions, and IO
Functions CIS 40 – Introduction to Programming in Python
Computational Thinking
Strings in Python Creating a string.
Computational Thinking
Imperative Programming
Learning Outcomes –Lesson 4
Strings.
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Presented by Mirza Elahi 10/29/2018
Variables and Expressions
Feedback Pace Different ideas for delivery Debugging strategies
GCSE Computing Lesson 6.
Variables, Data Types & Math
Introduction to Value-Returning Functions: Generating Random Numbers
15-110: Principles of Computing
CHAPTER 3: String And Numeric Data In Python
CS1110 Today: collections.
Variables, Data Types & Math
Introduction to Computer Science
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
CSE 231 Lab 12.
Imperative Programming
Introduction to Python
Python Creating a calculator.
Getting Started in Python
Data Types String holds alphanumeric data as text.
Presentation transcript:

More Basics of Python Common types of data we will work with String (str): a list of characters in order, surrounded by a pair of single or double quotes. E.g., ‘Hello’, ‘1234’, “How are you?” Integers (int): a whole number. E.g., 1, -5, 34567 Decimals (float): numbers with decimals. E.g. 1.0, 2.3, -3.4

Operations for Python Data Strings # concatenation x = ‘Hello’ y = ‘world!’ z = x + ‘ ‘ + y print(z) # hello world! # slicing x = ‘Hello world!’ y = x[0:5] z = x[6:] print(y) # Hello print(z) # world! # len() x = ‘Hello world!’ print(len(x)) # 12 Integers Floats # arithmetic x = 2 y = 3 print(x + y) # 5 print(x - y) # -1 print(x * y) # 6 print(x // y) # 0 print(x / y) # 0.6666 print(x ** y) # 8 # arithmetic x = 2.0 y = 3.0 print(x + y) # 5.0 print(x - y) # -1.0 print(x * y) # 6.0 print(x // y) # 0.0 print(x / y) # 0.6666 print(x ** y) # 8.0

Functions We’ll study functions more extensively. Here are some of the basics of a function Key word to designate this is a function Function inputs def compute( num1, num2 ): print(‘We saw ‘ + str(num1) + str(num2)) if num1 > num2: result = 2*num1 + num2 else: result = 2*num2 + num1 return result Function name Function result

Use of Functions A Python function is a block of code that does something Similar to a math function x = add(2, 3) y = compute(2, 3) answer = input(‘Enter a value : ‘) # answer a string n = int(input(‘Enter a value : ‘)) # n now an int

Use of Python Built-in Functions Python has a huge collection of built-in functions we can use. These functions are stored in various library files. To use Python functions in a library, we import the library first, then use any functions in that library. import random print(‘Some random values ‘, random.randint(3, 10))