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.

Slides:



Advertisements
Similar presentations
Objective: Dealing with data in C++ Agenda: Notes Essay Help.
Advertisements

Programming in python Lesson 2.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
Introduction to Python
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 6: Variables and constants.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
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 Damian Gordon. Variables We know what a variable is from maths. We’ve all seen this sort of thing in algebra: 2x – 10 = 0 2x = 10 X = 5.
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.
Python Programming Using Variables and input. Objectives We’re learning to use basic knowledge of variables combined with user input. Outcomes Continue.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
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.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Checking If User Input Is Numeric.  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 2.
Input, Output and Variables GCSE Computer Science – Python.
Numbers and arithmetic
Lesson 03: Variables and Types
CST 1101 Problem Solving Using Computers
GCSE COMPUTER SCIENCE Practical Programming using Python
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Lesson 1 - Sequencing.
Introduction to Python
Agenda Warmup Finish 2.4 Assignments
Unit 2 Smarter Programming.
Computer Science 3 Hobart College
Lesson 07: Strings Topic: Introduction to Programming, Zybook Ch 6, P4E Ch 6. Slides on website.
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
Computational Thinking
Computational Thinking
Thinking about programming
What are variables? Using input()
Learning to Program in Python
Computer Science and an introduction to Pascal
Computers & Programming Languages
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.
Teaching London Computing
Introduction to Primitive Data types
Changing one data type into another
Margaret Derrington KCL Easter 2014
Coding Concepts (Data- Types)
Feedback Pace Different ideas for delivery Debugging strategies
Lesson 03: Variables and Types
GCSE Computing Lesson 6.
Variables, Types, Operations on Numbers
Variables Kevin Harville.
Variables, Types, Operations on Numbers
What are variables? Using input()
Starter answer these questions in your book
Variables In today’s lesson we will look at: what a variable is
Python Basics with Jupyter Notebook
Thinking about programming
Thinking about programming
C# Revision Cards Data types
Unit 3: Variables in Java
What are variables? Using input()
Understanding Variables
Data Types and Maths Programming Guides.
GCSE Computing:: Selection (IF statements)
Introduction to Primitive Data types
Python Creating a calculator.
Section 6 Primitive Data Types
Presentation transcript:

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 numbers. (e.g. 1, 78, 0 and -54) Float - Decimal numbers (e.g. 3.5683, 98.74634, -6.3). Boolean - True or False

In some languages we have to tell the computer what data type a variable is going to be. Python, is able to decide the data type of the variable according to what value it is first given (or to use the correct term what it is initialised with). This can cause problems when we try to do something with the wrong data type. Let’s try it out copy the code “data_types” from your lesson page.

What happened? If you enter the numbers 5 and 4 it will output 54. This is because Python treats anything received through the input function as a string. We need to tell Python we want to convert this string to an integer before putting it into the variable. This is done using type casting. To cast data to an integer we use int()

Make some changes This time you will get an error in line 4: TypeError: Can't convert 'int' object to str implicitly

Why did this happen? This is because a and b are now integers. This means c is also now an integer (as it takes in the sum of two integers a + b). The problem arises when we then try and add c to a sentence as part of a string. So what do we do? The solution is to cast c back to a string when we use it using str().

Success 