Strings in Python Creating a string.

Slides:



Advertisements
Similar presentations
Getting Input in Python Assumes assignment statement, typecasts.
Advertisements

Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
Lists in Python.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Fall Week 4 CSCI-141 Scott C. Johnson.  Computers can process text as well as numbers ◦ Example: a news agency might want to find all the articles.
Strings CS303E: Elements of Computers and Programming.
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.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Lists vs Strings CMSC 201. Overview Python strings and lists are similar but different. Similar: syntax, access mechanisms, operators Different: Strings.
INLS 560 – S TRINGS Instructor: Jason Carter. T YPES int list string.
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.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Strings … operators Up to now, strings were limited to input and output and rarely used as a variable. A string is a sequence of characters or a sequence.
Input, Output and Variables GCSE Computer Science – Python.
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
String and Lists Dr. José M. Reyes Álamo.
Fundamentals of Python: First Programs
Computer Programming ||
Input and Output Upsorn Praphamontripong CS 1110
Formatting Output.
Python’s input and output
Variables, Expressions, and IO
Formatting Output.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Engineering Innovation Center
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CS 106A, Lecture 9 Problem-Solving with Strings
Introduction to Strings
Introduction to Strings
Python I/O.
Topics Introduction to File Input and Output
Creation, Traversal, Insertion and Removal
Chapter 8 More on Strings and Special Methods
Manipulating Text In today’s lesson we will look at:
Strings and Lists – the split method
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Programming Lecture 3
Patterns to KNOW.
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
Lists in Python Creating lists.
Variables and Expressions
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists in Python Outputting lists.
Section 1 Introduction To Programming
Fundamentals of Python: First Programs
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
functions: argument, return value
Intro to Computer Science CS1510 Dr. Sarah Diesburg
15-110: Principles of Computing
Topics Introduction to File Input and Output
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CISC101 Reminders Assignment 2 due today.
Introduction to Strings
Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
By Himanshi dixit 11th ’B’
Topics Introduction to File Input and Output
CS 1111 Introduction to Programming Spring 2019
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More Basics of Python Common types of data we will work with
Python Simple file reading
Introduction to Computer Science
Presentation transcript:

Strings in Python Creating a string

Creating a string There are many different ways to create a string The simplest way is to hard code it into your program mystring = “Hello” Remember individual characters of mystring cannot be changed afterward (strings are immutable) Many of the string methods return new strings newstring = mystring.upper() The typecast str will create a string from another data type mynumstring = str(num)

Getting a string from input When you read from the keyboard, the input function will always return a string myname = input(“What’s your name? “) When you learn about external files, one thing you do is read from them (see Chapter 10) The input from a file always comes in as a string or list of strings

Other ways to create a string You can build up a string one character at a time The pattern is very similar to an accumulator You initialize a variable to an empty string new_one = “” Then in a loop you concatenate the new character onto the variable new_one = new_one + ch