Introduction to Python Data Types and Variables

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

1 C++ Syntax and Semantics The Development Process.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CPS120: Introduction to Computer Science
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Lecture 3 Introduction to Computer Programming CUIT A.M. Gamundani Presentation Layout from Lecture 1 Background.
Welcome to AP Computer Science A We use the Java language, but this class is much more rigorous than Intro to Java More programming, but also more theory.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
CPS120: Introduction to Computer Science Variables and Constants.
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.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Introduction to Python Lesson 2a Print and Types.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Fundamentals 2.
Bill Tucker Austin Community College COSC 1315
CMSC201 Computer Science I for Majors Lecture 03 – Variables
CST 1101 Problem Solving Using Computers
User Interaction and Variables
ITM 352 Data types, Variables
LESSON 2 Basic of C++.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Topic: Python’s building blocks -> Variables, Values, and Types
Objectives Identify the built-in data types in C++
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Learning to Program in Python
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
2.1 Parts of a C++ Program.
Varying very versatile variables
Variables ICS2O.
Variables in C Topics Naming Variables Declaring Variables
Unit-1 Introduction to Java
C++ Data Types Data Type
Variables in C Topics Naming Variables Declaring Variables
Variables Kevin Harville.
Arrays.
Chapter 2: Java Fundamentals
Chapter 2: Introduction to C++.
Welcome to AP Computer Science A!
Primitive Types and Expressions
Unit 3: Variables in Java
Understanding Variables
Data Types and Maths Programming Guides.
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
Variables in C Topics Naming Variables Declaring Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables in C Topics Naming Variables Declaring Variables
Basic Programming Lab C.
Introduction to Pointers
Variables in C Topics Naming Variables Declaring Variables
Data Types and Arithmetic in C
Presentation transcript:

Introduction to Python Data Types and Variables ICS 3U0

Today’s Agenda Variables Data Types Declaring and Assigning Variables Strings, Integers and Floating Numbers

Storage and Variables In order to interact with the outside world, programs have to accept Input. Before doing this, however, we need to discuss storage and variables. If the computer asks the user for their name, age, grade, address, or any other information, it should remember that information. Information is stored in memory. A variable is a specific location in memory. It is called a “variable” because its value can be changed (varies).

Declaring Variables When we declare a variable: a space is reserved in memory for that data a name is reserved to identify that data the type of data stored in the variable is specified (for example, is this variable going to be a string or integer) Once a name is reserved, you cannot declare another variable by the same name.

Three Basic Data Types int – an integer value is a positive or negative whole number (..., -3, -2, -1, 0, 1, 2, 3, …) float – a real number involves decimals, such as 0.5, 0.33, 10.7. You can also represent integers as reals, but try to avoid this (-3.0, 4.0) str – a string value is a collection of characters, such as a name, address, or other combinations of letters and numbers

How to Declare Variables in Python To create (or declare) a variable, assign it a value. >>> number = 42 The equals sign, =, is called the assignment operator, since it is used to assign a value to a variable. We can now refer to the variable by its name, anytime we want. For example, to check its current value, type the variable’s name. >>> number 42

Example - Integers a = 8 b = 6-7 print(a, b) What does the type function do? a = 8 b = 6-7 print(a, b) print("The value of a is:", a) print("The value of b is:", b) print(type(a)) print(type(b))

Example - Floating Numbers print(a, b) print("The value of a is:", a) print("The value of b is:", b) print(type(a)) print(type(b))

Example - Strings a = "Mr. Cookit" b = "LOVES programming" print(a, b) print("The value of a is:", a) print("The value of b is:", b) print(type(a)) print(type(b))

Naming Variables – The RULES Variables should start with a lower case letter. Variables can start with an upper case letter or an underscore, but those are special cases and should not be done on a normal basis. After the first lower case letter, the variable may include uppercase and lowercase letters, along with numbers and underscores. Variables may not include spaces.

Naming Variables – More RULES The official style guide for Python (yes, programmers really wrote a book on style) says that multi-word variable names in Python should be separated by underscores. For example, use …. hair_style and not hairStyle. 

Naming Variables – Examples Either of these are fine with me ... I investigated and ALOT of Python developers use firstName as opposed to first_name

Exercises - Variables Complete Exercise 1.6 – Variables Typecasting