Advanced Algorithms and Computational Models (module A)

Size: px
Start display at page:

Transcription

1 Advanced Algorithms and Computational Models (module A) Giacomo Fiumara / 34

2 Python's built-in classes A class is immutable if each object of that class has a xed value upon instantiation that cannot subsequently be changed For example, the class float is immutable, since once an instance has been created, its value cannot be changed Class Description Immutable bool Boolean value y int integer y float oating-point number y list mutable sequence of objects n tuple immutable sequence of objects y str character string y set unordered set of distinct objects n frozenset immutable form of set class y dict associative mapping (aka dictionary) n 2 / 34

3 The bool class The bool class is used to manipulate Boolean values The two only instances of the class are expressed as the literals False and True The default constructor, bool() returns False goofy = bool() pluto = False Python allows the creation of a Boolean value from a non-boolean type using the syntax bool(huey) for value huey The interpretation depends upon the type of the parameter numbers evaluate to False if zero, and True if nonzero Strings and lists evalutate to False if empty, and True if nonempty 3 / 34

4 The int class The int class is designed to represent integer values with arbitrary magnitude Unlike Java and C++ which support dierent integer types with dierent precision, Python automatically chooses the internal representation for an integer based upon the magnitude of its value In some contexts may be useful to express an integral value using binary, octal or hexadecimal. For example: 0b o755 0x9ab 4 / 34

5 The int class 5 / 34

6 The int class The constructor int() returns value 0 by default However, it can be used only to construct an integer value starting from an existing value of another type For example 6 / 34

7 The int class If goofy represents a oating-point value, int(goofy) produces the truncated value of goofy The constructor can be used to parse a string which is presumed to represent an integral value: int( 150 ) produces the integer value 150 By default, the string must use base 10 If conversion from another base is desired, that base can be indicated as a second optional parameter, for example: int( 7f, 16) evaluates to the integer / 34

8 The float class The float class is the sole oating-point type in Python with a xed-precision Literal forms are 98.6 and 10e3 The constructor form of float() returns 0.0. When given a parameter, the constructor attempts to return the equivalent oating-point value For example, the call float(2) returns 2.0 If the parameter to the constructor is a string (float( 14.3 )), it attempts to parse the string as a oating-point value 8 / 34

9 The list class A list instance stores a sequence of objects A list is a referential structure, as it technically stores a sequence of references to its elements Lists are array-based sequenced and are zero-indexed (a list of length n has elements indexed from 0 to n 1 inclusive) Lists are probably the most used container types in Python, thay have many valuable behaviors, including the ability to dynamically expand and contract their capacities as needed 9 / 34

10 The list class Python uses the characters [ and ] as delimiters for a list literal, with [] being en empty list. For example: [ one, two, three ] If identiers a, b, c have been established, the following syntax is correct: [a, b, c] 10 / 34

11 The list class 11 / 34

12 The list class The list() constructor produces an empty list by default However, the constructor will accept any parameter that is of iterable type (e.g., strings, lists, tuples, sets, dictionaries) For example: 12 / 34

13 The tuple class The tuple class provides an immutable version of a sequence Python uses the characters ( and ) to delimit a tuple, with () being an empty tuple To express a tuple of length one as a literal, a comma must be placed after the element (within the parentheses). For example: 13 / 34

14 The str class The str class is designed to represent an immutable sequence of characters based upon the Unicode international character set Strings have a more compact internal representation than lists and tuples 14 / 34

15 The str class Strings can be enclosed in single quotes, as in ciao or double quotes, as in ciao The second choice is conveniente, in particular when using another of the quotation characters as in L attimo Alternatively, the quote delimiter can be designated using a backslash (the so-called escape character) as in L attimo Of course, even the backslash must itself be escaped (if necessary) Python also supports the delimiter or The main advantage of these delimiters is that strings naturally contain newlines 15 / 34

16 The set and frozenset classes The set class represents the mathematical notion of a set, namely a collection of distinct elements without an inherent order The major advantage of using a set is that it has a highly optimized method for checking whether a specic element is contained in the set Two main restrictions: The set does not maintain the elements in any particular order Only instances of immutable elements can be added to a Python set (integers, oating-point numbers, character strings) Python uses { and } as delimiters for a set, for example {1, 4, 2, 9} or aa, b, ciao There is an important exception: {} represents an empty dictionary (not a set). To represent an empty set the constructor set() must be invoked 16 / 34

17 The set and frozenset classes 17 / 34

18 The dict class The dict class represents a dictionary, from a set of distinct keys to associated values For example, a dictionary might map from unique student ID numbers, to larger student records (name, address, course grades) The literal form {} represents an empty dictionary, while a nonempty dictionary is expressed using a comma-separated series of key: value pairs For example: phone = { john : 4040, joe : 4041, kate : 4042} 18 / 34

19 Expressions, Operators and Precedence Logical Operators Python supports the following keyword operators for Boolean values: Operator not and or Description Unary negation Conditional and Conditional or The and and or operators short-circuit, in that they do not evaluate the second operand if the result can be determined based on the value of the rst operand 19 / 34

20 Expressions, Operators and Precedence Equality Operators Python supports the following operators to test two notions of equality: Operator Description is same identity is not dierent identity == equivalent!= not equivalent 20 / 34

21 Expressions, Operators and Precedence Equality Operators The expression a is b evaluated to True precisely when identiers a and b are aliases for the same object The expression a == b tests a more general notion of equivalence: If identiers a and b refer to the same object, then a == b evaluates to True If identiers refer to dierent objects that are equivalent, then a == b evaluates to True The precise notion of equivalence depends on the data type: two strings are considered equivalent if they match character for character, while two sets are equivalent if they have the same content, irrispective of order In general, use of is and is not should be reserved for situations in which it is necessary to detect true aliasing 21 / 34

22 Expressions, Operators and Precedence Comparison Operators Data types may dene a natural order via the following operators Operator Description < less than <= less than or equal to > greater than >= greater than or equal to These operators have expected behavior for numeric types They are dened lexicographically, and case sensitively, for strings An exception is raised if operands have incomparable types 22 / 34

23 Expressions, Operators and Precedence Comparison Operators 23 / 34

24 Expressions, Operators and Precedence Comparison Operators 24 / 34

25 Expressions, Operators and Precedence Arithmetic Operators Python supports the following arithmetic operators: Operator Description + addition subtraction multiplication / true division // integer division % modulo operator 25 / 34

26 Expressions, Operators and Precedence Arithmetic Operators The use of addition, subtraction and multiplication is straightforward (if both operands have type int, then the result is int as well; if one or both operands have type float, the result will be float) In Python, / denotes the so-called true division, returning the oating-point result of the computation, while // is used to perform the integral calculation and % returns the remainder of the integer division 26 / 34

27 Expressions, Operators and Precedence Arithmetic Operators Where: Python extends the semantics of // and % to cases where one or both operands are negative Let's assume that n, is the dividend m, is the divisor n = q m + r q, is the quotient (q = n//m) r, is the remainder (r = n%m) 27 / 34

28 Expressions, Operators and Precedence Arithmetic Operators n = q m + r When the divisor is positive, Python guarantees that 0 r < m As a consequence, we have that 27//4 = 7 and 27%4 = 1 We have indeed that = 27 When the divisor is negative, Python guarantees that m < r 0 As a consequence, we have that 27//( 4) = 7 and 27% 4 = 1 We have indeed that 7 ( 4) 1 = / 34

29 Expressions, Operators and Precedence Bitwise Operators Python supports the following bitwise operators for integers: Operator Description bitwise complement (prex unary operator) & bitwise and bitwise or ˆ bitwise exclusive-or << shift bits left, lling in with zeros >> shift bits right, lling in with sign bit 29 / 34

30 Expressions, Operators and Precedence Sequence Operators Each of Python's built-in sequence types (str, tuple, list) support the following operator syntaxes: Operator Description s[j] element at index j s[start : stop] slice including indices [start, stop] s[start : stop : step] slice including indices start, start+step, start +2 step,... up to but not equalling or stop s + t concatenation of sequences k s shorthand for s + s + s +... (k times) val in s containment check val not in s non-containment check 30 / 34

31 Expressions, Operators and Precedence Sequence Operators Python relies on zero-indexing of sequences (a sequence has n elements indexed from 0 to n 1 inclusive) It is supported the use of negative indices, which denote a distance from the end of the sequence: index 1 denotes the last element, index 2 the second to last and so on Python uses a slicing notation to describe subsequences of a sequence Slices are described as half-open intervals, with a start index (included) and a stop index (excluded) An optional step index, possibly negative, can be indicated as a third parameter of a slice If a start or stop index is omitted in the slicing notation, it is presumed to designate the extreme of the original sequence 31 / 34

32 Expressions, Operators and Precedence Sequence Operators 32 / 34

33 Expressions, Operators and Precedence Sequence Operators Lists are mutable, therefore the following syntax is used to replace an element at a given index s[j] = val Lists also support a syntax to remove the designated element from the list: del s[j] Slice notation can also be used to replace or delete a sublist 33 / 34

34 Expressions, Operators and Precedence Sequence Operators The notation val in s can be used for any of the sequences to see if there is an element equivalent to val in the sequence All sequences dene comparison operators based on lexicographic order, performing an element by element comparison until the rst dierence is found. For example: 34 / 34

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

Data Handing in Python

Data Handing in Python As per CBSE curriculum Class 11 Chapter- 3 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Introduction In this chapter we will learn data types, variables, operators

Operators and Expressions

Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 In this course you will start by building a compiler for a language called Xi. This is an imperative,

Operators. Java operators are classified into three categories:

Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

Language Reference Manual simplicity

Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

Operators in C. Staff Incharge: S.Sasirekha

Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

1 CS580W-01 Quiz 1 Solution

1 CS580W-01 Quiz 1 Solution Date: Wed Sep 26 2018 Max Points: 15 Important Reminder As per the course Academic Honesty Statement, cheating of any kind will minimally result in receiving an F letter grade

Python Class-Lesson1 Instructor: Yao

Python Class-Lesson1 Instructor: Yao What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined

Lecture no

Advanced Algorithms and Computational Models (module A) Lecture no. 3 29-09-2014 Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 28 Expressions, Operators and Precedence Sequence Operators The following

Babu Madhav Institute of Information Technology, UTU 2015

Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?

Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

Script language: Python Data structures

Script language: Python Data structures Cédric Saule Technische Fakultät Universität Bielefeld 3. Februar 2015 Immutable vs. Mutable Previously known types: int and string. Both are Immutable but what

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

L-System Fractal Generator: Language Reference Manual

L-System Fractal Generator: Language Reference Manual Michael Eng, Jervis Muindi, Timothy Sun Contents 1 Program Definition 3 2 Lexical Conventions 3 2.1 Comments...............................................

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

Variables, Constants, and Data Types

Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

Python memento TI-Smart Grids

Python memento TI-Smart Grids Genoveva Vargas-Solar French Council of Scientific Research, LIG genoveva.vargas@imag.fr http://vargas-solar.com/data-centric-smart-everything/ * This presentation was created

DaMPL. Language Reference Manual. Henrique Grando

DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4

egrapher Language Reference Manual

egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

Java Primer 1: Types, Classes and Operators

Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

UNIVERSITÀ DI PADOVA. < 2014 March >

UNIVERSITÀ DI PADOVA < 2014 March > Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined syntax. Easy-to-read: Python code is much more clearly defined and visible

Python - Variable Types. John R. Woodward

Python - Variable Types John R. Woodward Variables 1. Variables are nothing but named reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Here n is a variable name. The value of that variable is 176.

UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

Chapter 2 Working with Data Types and Operators

JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

GraphQuil Language Reference Manual COMS W4115

GraphQuil Language Reference Manual COMS W4115 Steven Weiner (Systems Architect), Jon Paul (Manager), John Heizelman (Language Guru), Gemma Ragozzine (Tester) Chapter 1 - Introduction Chapter 2 - Types

CS109A ML Notes for the Week of 1/16/96. Using ML. ML can be used as an interactive language. We. shall use a version running under UNIX, called

CS109A ML Notes for the Week of 1/16/96 Using ML ML can be used as an interactive language. We shall use a version running under UNIX, called SML/NJ or \Standard ML of New Jersey." You can get SML/NJ by

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

Learning Language Reference Manual 1 George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104) A. Introduction Learning Language is a programming language designed

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

FRAC: Language Reference Manual

FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

GE8151 - PROBLEM SOVING AND PYTHON PROGRAMMING Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING 1) Define Computer 2) Define algorithm 3) What are the two phases in algorithmic problem solving? 4) Why

Operators in java Operator operands.

Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

Number System. Introduction. Decimal Numbers

Number System Introduction Number systems provide the basis for all operations in information processing systems. In a number system the information is divided into a group of symbols; for example, 26

Chapter 4 : Informatics Practices. Data Handling. Class XI ( As per CBSE Board) Visit : python.mykvs.in for regular updates

Chapter 4 : Informatics Practices Class XI ( As per CBSE Board) Data Handling Introduction Most of the computer programming language support data type, variables,operator and expression like fundamentals.python

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

CIS192: Python Programming

CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms

CS 115 Lecture 4. More Python; testing software. Neil Moore

CS 115 Lecture 4 More Python; testing software Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 8 September 2015 Syntax: Statements A statement

Full file at

Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

Chapter 3: Operators, Expressions and Type Conversion

101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

PYTHON- AN INNOVATION

PYTHON- AN INNOVATION As per CBSE curriculum Class 11 Chapter- 2 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Python Introduction In order to provide an input, process it and to receive

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

A Java program contains at least one class definition.

Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

CS 115 Data Types and Arithmetic; Testing Taken from notes by Dr. Neil Moore Statements A statement is the smallest unit of code that can be executed on its own. So far we ve seen simple statements: Assignment:

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Unit-2 (Operators) ANAND KR.SRIVASTAVA 1 Operators in C ( use of operators in C ) Operators are the symbol, to perform some operation ( calculation, manipulation). Set of Operations are used in completion

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

Expression and Operator

Expression and Operator Examples: Two types: Expressions and Operators 3 + 5; x; x=0; x=x+1; printf("%d",x); Function calls The expressions formed by data and operators An expression in C usually has a

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

Collections. Lists, Tuples, Sets, Dictionaries

Collections Lists, Tuples, Sets, Dictionaries Homework notes Homework 1 grades on canvas People mostly lost points for not reading the document carefully Didn t play again Didn t use Y/N for playing again

1 Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

Chapter 6 Primitive types

Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

CS95003 - Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / 2014 Subjects 1) Beginning with Python 2) Variables 3) Strings 4) Basic arithmetic operators 5) Flow control 6) Comparison

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

SECTION II: LANGUAGE BASICS

Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

2 nd Week Lecture Notes

2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

Chapter 2: Using Data

Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

CSC Web Programming. Introduction to JavaScript

CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

Declaration and Memory

Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

4 Programming Fundamentals. Introduction to Programming 1 1

4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

THIS CHAPTER DESCRIBES PYTHON S BUILT-IN OPERATORS as well as the precedence

4 Operators and Expressions THIS CHAPTER DESCRIBES PYTHON S BUILT-IN OPERATORS as well as the precedence rules used in the evaluation of expressions. s on Numbers The following operations can be applied

Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

Programming Lecture 3

Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

Chapter 3 : Computer Science. Class XI ( As per CBSE Board) Data Handling. Visit : python.mykvs.in for regular updates

Chapter 3 : Computer Science Class XI ( As per CBSE Board) Data Handling Introduction Most of the computer programming language support data type, variables,operator and expression like fundamentals.python

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

COMP1730/COMP6730 Programming for Scientists Data: Values, types and expressions. Lecture outline * Data and data types. * Expressions: computing values. * Variables: remembering values. What is data?

JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

Java Basic Datatypees

Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,

Department of Computer Science

Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and

Introduction to Python

Introduction to Python خانه ریاضیات اصفهان فرزانه کاظمی زمستان 93 1 Why Python? Python is free. Python easy to lean and use. Reduce time and length of coding. Huge standard library Simple (Python code

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS OPERATORS Review: Data values can appear as literals or be stored in variables/constants Data values can be returned by method calls Operators: special symbols

Outline. Data and Operations. Data Types. Integral Types

Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions Data and Operations Data and Operations

Algorithmic "imperative" language

Algorithmic "imperative" language Undergraduate years Epita November 2014 The aim of this document is to introduce breiy the "imperative algorithmic" language used in the courses and tutorials during the

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,