COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University 2010-2011.

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
Advertisements

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.
Lists Introduction to Computing Science and Programming I.
Strings. A string is a series of characters Characters can be referenced by using brackets The first character is at position 0 mystring = “the” letter.
JavaScript, Third Edition
Geography 465 Assignments, Conditionals, and Loops.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Guide to Programming with Python
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Python Programming Chapter 7: Strings Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Programming in Python Part III Dr. Fatma Cemile Serçe Atılım University
Built-in Data Structures in Python An Introduction.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
More Strings CS303E: Elements of Computers and Programming.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
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.
3 Basics © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming.
12 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Python Strings. String  A String is a sequence of characters  Access characters one at a time with a bracket operator and an offset index >>> fruit.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
ICS102 Lecture 8 : Boolean Expressions King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Python Arithmetic Operators OperatorOperationDescription +AdditionAdd values on either side of the operator -SubtractionSubtract right hand operand from.
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.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
Random Functions Selection Structure Comparison Operators Logical Operator
Guide to Programming with Python Chapter Four Strings, and Tuples; for Loops: The Word Jumble Game.
GCSE COMPUTER SCIENCE Practical Programming using Python
Python Basics.
String and Lists Dr. José M. Reyes Álamo.
G. Pullaiah College of Engineering and Technology
CSc 120 Introduction to Computer Programing II Adapted from slides by
Module 4 String and list – String traversal and comparison with examples, List operation with example, Tuples and Dictionaries-Operations and examples.
Strings Part 1 Taken from notes by Dr. Neil Moore
CHAPTER 7 STRINGS.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Computers & Programming Languages
Data types Numeric types Sequence types float int bool list str
Strings.
Introduction to Programming
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Basic String Operations
CHAPTER 3: String And Numeric Data In Python
Intro to Computer Science CS1510 Dr. Sarah Diesburg
The Data Element.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Basic String Operations String Slicing
Introduction to Computer Science
Introduction to Computer Science
Sequences Sequences are collections of data values that are ordered by position A string is a sequence of characters A list is a sequence of any Python.
Topics Basic String Operations String Slicing
The Data Element.
By Himanshi dixit 11th ’B’
Understanding Variables
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Topics Basic String Operations String Slicing
Conditionals.
COMPUTING.
Presentation transcript:

COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University

Conditional Expressions Boolean expressions an expression that is either true or false x == y # x is equal to y x != y # x is not equal to y x > y # x is greater than y x < y # x is less than y x >= y # x is greater than or equal to y x <= y # x is less than or equal to y >>> 5 == 5 True >>> 5 == 6 False True and False are special values that are built into Python. !!!Remember that = is an assignment operator and == is a comparison operator

Strings Strings are made up of smaller pieces—characters. The bracket operator selects a single character from a string. >>> fruit = "banana" >>> letter = fruit[1] >>> print letter Output: a The expression in brackets is called an index Index starts at zero

Length The len function returns the number of characters in a string: >>> fruit = "banana" >>> len(fruit) Output: 6 length = len(fruit) last = fruit[length] # ERROR! That won’t work. It causes the runtime error IndexError: string index out of range. The reason is that there is no 6th letter in "banana“ the six letters are numbered 0 to 5 length = len(fruit) last = fruit[length-1]

Exercise As an exercise, write a function that takes a string as an argument and outputs the letters backward, one per line.

String Operations

String Slices A segment of a string is called a slice. Selecting a slice is similar to selecting a character:

String Comparison The comparison operators work on strings. In Python, uppercase letters come before all the lowercase letters. Zebra, comes before banana.

Cannot change Strings! A string cannot be changed in Python! Immutable Create new strings from bits and pieces of old

String Functions ( import string )