Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
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.
Introduction to Python
Introduction to Methods. How do we use Methods in Java? Let us start by creating one which displays “hello” on Dos Prompt.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Group practice in problem design and problem solving
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Introducing Python CS 4320, SPRING Format: Field widths and Alignment The string representation of a value can be padded out to a specific width.
Instructor - C. BoyleFall Semester
Lists CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
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.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Course A201: Introduction to Programming 09/30/2010.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
More Strings CS303E: Elements of Computers and Programming.
Mr. Fowler Computer Science 14 Feb 2011 Strings in Python.
 How do you represent a number with no value?  Mathematicians defined the “number” 0 (zero)  How do we represent a string with no value?  Use an empty.
Last Week Modules Save functions to a file, e.g., filename.py The file filename.py is a module We can use the functions in filename.py by importing it.
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
COP 2510 Chapter 6 - Functions. Random function (randint) #import the desired function import random #integer random number in the range of 1 through.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
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.
Computer Science 18 Feb 2011 Strings in Python. Introduction Prior experience  Defining string variables  Getting user input  Printing strings Lesson.
Introduction to Programming
GCSE COMPUTER SCIENCE Practical Programming using Python
String and Lists Dr. José M. Reyes Álamo.
G. Pullaiah College of Engineering and Technology
String Manipulation Part 1
Introduction to Programming
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Generating Random Numbers
Data Types and Conversions, Input from the Keyboard
Repetition: the for loop
String Manipulation.
Introduction to Strings
Introduction to Strings
Decision Structures, String Comparison, Nested Structures
Decision Structures, String Comparison, Nested Structures
Fundamentals of Programming I Number Systems
Bryan Burlingame 17 October 2018
Python - Strings.
Strings.
4. sequence data type Rocky K. C. Chang 16 September 2018
CSC 221: Introduction to Programming Fall 2018
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
Introduction to Programming
Notes about Homework #4 Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming:
Fundamentals of Python: First Programs
Introduction to Strings
CHAPTER 3: String And Numeric Data In Python
Functions continued.
Bryan Burlingame 13 March 2019
Introduction to Computer Science
CSE 231 Lab 3.
Introduction to Strings
Introduction to Programming
Formatting Output.
L L Line CSE 420 Computer Games Lecture #4 Working with Data.
Class code for pythonroom.com cchsp2cs
Introduction to Strings
More Basics of Python Common types of data we will work with
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
Presentation transcript:

Introduction to Computer Science CSC115

Built-in/Helper Functions

Helper Functions len() – this function is used to provide the length of strings, and many other data structures that we will use later. For now, lets see how many characters the string “Hello CSC115” contains:

Helper Functions Looping through a string Traditional Loop Pythonic Loop

Helper Functions Check whether a string contains ’@’ – Traditional

Helper Functions Check whether a string contains ‘@’ – Pythonic

Slicing Strings >>> print(str[-1]) ‘d’ >>> x = "Hello World!" >>> print(str[::]) ‘Hello World’ >>> print(str[0:3]) ‘Hel’ >>> print(str[3:5]) ‘lo’ >>> x[2:] 'llo World!’ >>> x[:2] 'He’ >>> x[:-2] 'Hello Worl’ >>> x[-2:] 'd!’ >>> x[2:-2] 'llo Worl’ >>> print(str[-1]) ‘d’ print(str[1:]) ‘ello world’

Helper Functions upper() is a built-in function that will return a given string in capital case Lower() is a built-in function that will return a given string in lower case

Helper Functions random() is a built-in function that generates random values that can be floats or integers We can specify the range of values to return In order to use this library, we need to import random – which is a built in library in Python

Random The following code will generate 10 random integer values between 0 and 9 (range)

Random The following code will generate 10 random floating-point values between 0 and 9 (range)

Random The following code will generate 10 random floating-point values between 0 and 9 (range) – with formatted decimals

Decimal Format {0} tells format to print the first argument Everything after the colon ( : ) specifies the format_spec .3 sets the precision to 3 g removes insignificant zeros For g and G types, trailing zeros are not removed For f, F, e, E, g, G types, the output always contains a decimal point For o, x, X types, the text 0, 0x, 0X, respectively, is prepended to non-zero numbers.