UNIT 5. String Functions and Random Numbers

Size: px
Start display at page:

Download "UNIT 5. String Functions and Random Numbers"

Transcription

1 UNIT 5 String Functions and Random Numbers

2 DAY 1 String data type String storage in data String indexing

3 I can.. Explain the purpose of the string variable type and how it is stored in memory. Explain indexing of a string (forwards and backwards). Explain and use concatenation and repetition of strings.

4 String Variable Stores text Sequence of characters Assigned using double quotations Ex: str1 = hello str2 = you

5 Type function Determines the type of variable stored in a variable name. Important to know the TYPE of data stored in a variable, as the computer must interact with numeric data different than it interacts with text data type(<variable name>)

6 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L1StringBasics

7 In Class Project Type the Following (Page 1 of 2) # Simple Conditional If Program # **Insert Today s Date Here** var1 = 4 # creates int variable with value 4 var2 = 5.5 # creates float variable with value 5 var3 = four # creates string variable with value four type1 = type(var1) # saves type of variable 1 type2 = type(var2) # saves type of variable 2 type3 = type(var3) # saves type of variable 3

8 In Class Project Type the Following (Page 2 of 2) print( variable 1 type :, type1) # prints variable type 1 to screen print( variable 2 type :, type2) # prints variable type 2 to screen print( variable 3 type :, type3) # prints variable type 3 to screen

9 Output of Program variable 1 type: <class int > variable 2 type: <class float > variable 3 type: <class string > **Using this method can be helpful when writing a program to check variable types in the program**

10 Numbers vs. Strings Think about what we ve learned so far what operations can we perform with numbers that we can either NOT perform with strings OR work differently with strings.

11 Numbers vs. Strings Throughout this unit we will learn about strings and their functions! Some of the number functions (+, *) can be used on strings but they act in different ways Some functions can ONLY be used with string variables

12 How are Strings Stored in Memory? Character (String) H e l l o Location Name of variable represents a LOCATION in memory Location represents where the string of text begins Each character is stored in order at a specific INDEX The index begins at 0, and increases by 1 for each stored character Spaces, numbers, letters, special characters ALL have an index location in the string

13 Practice Use the string variable below to determine the index of the characters listed in each question. If the character occurs multiple times, list multiple locations Str1 = I love programming & math! 1) Location of: v 4) Location of: p 2) Location of: o 5) Location of: & 3) Location of: m 6) Location of:!

14 Practice Use the string variable below to determine the index location of the characters listed in each question. If the character occurs multiple times, list multiple index locations Str1 = I love programming & math! 1) Location of: v 2) Location of: p 4 7 3) Location of: o 4) Location of: & 3, ) Location of: m 5) Location of:! 13, 14, 21 25

15 Accessing a Specific Location Sometimes you want to access a specific index of a string <string variable name>[<index number>]

16 Practice Use the string below to identify the character represented by each index value below str1 = Help, I m stuck! 1) str1[0] 3) str1[4] 2) str1[8] 5) str[12] 5) str[16]

17 Practice Use the string below to identify the character represented by each index value below str1 = Help, I m stuck! 1) str1[0] 2) str1[4] H, 3) str1[8] 4) str[12] m u 5) str[16] error out of range no character at index 16

18 Index and For Loop Another fantastic way to show indexing is to use a for loop

19 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L2StringIndex

20 In Class Project Type the Following (Page 1 of 1) # String Index For Loop # **Insert Today s Date Here** message = Hello, Ms. Wardecke! # string declared/initialized for i in message : print(i) # cycle through each character in message # print each character

21 In Class Project Alter the Following (Page 1 of 1) # String Index For Loop # **Insert Today s Date Here** message = Hello, Ms. Wardecke! # string declared/initialized for i in message : # cycle through each character in message print(i,end= ) # print each character # end with space after each **Experiment change the space to something else**

22 Print Statement Additional Option Sometimes instead of a new line you want your print statement to end with a space or character. print(<string to print>, end = <end of print> )

23 Backwards Indexing Prediction: What happens when a negative number is placed in the index?!?!

24 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L3BackwardsIndex

25 In Class Project Type the Following (Page 1 of 1) # String Index For Loop # **Insert Today s Date Here** message = Hello, Ms. Wardecke! # string declared/initialized for i in range(10) : print( index #-, I, :, end= ) print(message[-i]) # index number # character at index

26 Backwards Indexing Character (String) H e l l o Location Backwards Indexing signals to the computer to count the characters backwards Notice backwards DOES NOT start with 0 Index 0 is always the FIRST character in the string

27 Practice Use the string below to identify the character represented by each index value below str1 = Help, I m stuck! 1) str1[0] 2) str1[-4] 3) str1[-8] 4) str[-12] 5) str[-16]

28 Practice Use the string below to identify the character represented by each index value below str1 = Help, I m stuck! 1) str1[0] 2) str1[-4] H u 3) str1[-8] 4) str[-12] m, 5) str[-16] H

29 Predict: What will the following do?? str1 = My str2 = name str3 = is str4 = Bob str5 =! str6 = str1 + str2 + str3 + str4 + str5 print(str6)

30 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L4Concatenation

31 In Class Project Type the Following (Page 1 of 1) # Concatenation # **Insert Today s Date Here** str1 = My # declare and initialize string 1 str2 = name # declare and initialize string 2 str3 = is # declare and initialize string 3 str4 = Bob # declare and initialize string 4 str5 =! # declare and initialize string 5 str6 = str1 + str2 + str3 + str4 + str5 # concatenate string 6 print(str6) # print string 6 to the screen

32 Output MynameisBob! What does python do when you place a + between strings??

33 Concatenation The addition of strings When strings are added they are strung together with NO ADDED SPACES BETWEEN This is called concatenation Strings are concatenated (added together) exactly as they are written and combined into one string!

34 Predict: What will the following do?? str1 = My str2 = name str3 = 3*str1 + 2*str2 print(str3)

35 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L5Repetition

36 In Class Project Type the Following (Page 1 of 1) # Repetition # **Insert Today s Date Here** str1 = hello str2 = world print(3*str1 + 2*str2)

37 Repetition The multiplication of strings When strings are multiplied the computer will output the same string multiple times with no spaces

38 Write the output for the following chunks of code var1 = blue var2 = 11 var3 = purple var4 = 14 1) print(var1, var2) 2) var5 = var1 + var2 print(var5) 3) print(3*var3) 4) print(3*var4) 5) var6 = var1 + + var3 print(var6)

39 Write the output for the following chunks of code var1 = blue var2 = 11 var3 = purple var4 = 10 1) print(var1, var2) blue 11 2) var5 = var1 + var2 blue11 print(var5) 3) print(3*var3) purplepurplepurple 4) print(3*var4) 30 **NOTE: var4 is an INTEGER** 5) var6 = var1 + + var3 blue purple print(var6)

40 Homework Worksheet 5A

41

42 DAY 2 String slicing.

43 I can.. Explain string splicing and how strings can be broken up into parts.

44 Slicing Slicing = purposefully cutting a string based on index location

45 4 Main Types of Slicing 1. <string name>[:]\ 2. <string name>[<number>:<number>] 3. <string name>[<number>:] 4. <string name>[:<number>]

46 Complete Slicing Investigation Complete the Slicing Investigation By the end, you should be able to explain how the segments of code below work in Python Once everyone is done we will regroup, and discuss the findings 1. <string name>[:] 2. <string name>[<number>:<number>] 3. <string name>[<number>:] 4. <string name>[:<number>]

47 <string name>[:] Will print the entire string

48 <string name>[<number>:<number>] Prints a substring of the string The number before the colon represents the STARTING index where the substring should start The number after the colon represents the index AFTER the last character in the substring Ex: str1[ I love computing! str1[2:10] = love com (indices 2-9)

49 <string name>[<number>:] Prints a substring of the string The number before the colon represents the STARTING index where the substring should start Since there is no ending index, the substring will print until the END of the string Ex: str1[ I love computing! str1[2:] = love computing! (indices 2-end)

50 <string name>[:<number>] Prints a substring of the string Since there is no starting index, the substring will start at the beginning of the string The number after the colon represents the index AFTER the last character in the substring Ex: str1[ I love computing! Str1[:10] = I love com (indices start - 9)

51 Practice Use the string below to identify the substring represented by the index slicing below. str1 = Help, I m stuck! 1) str1[:] 4) str1[4:8] 2) str1[3:11] 5) str[:7] 3) str[2:]

52 Practice Use the string below to identify the substring represented by the index slicing below. str1 = Help, I m stuck! 1) str1[:] 2) str1[4:8] Help, I m stuck!, I 3) str1[3:11] 4) str[:7] p, I m s Help, I 5) str[2:] lp, I m stuck!

53 Practice on Your Own: User Name Creation Create a program that meets the following conditions: When a student attends MHS they receive a user name consisting of his or her 4 and 4 4 and 4 : First 4 letters of first name, first four letters of last name Write a program that will prompt the user for his or her first name and for his or her last name. The program will then output the student s username **You may assume every student has a 4 letter first and last name**

54 Homework Worksheet 5B

55

56 DAY 3 ASCII Code and String Length

57 I can.. Explain and use the length, character, and ordinal number functions with strings.

58 ASCII Code Remember = computers ONLY can read machine language which is written in binary (0s and 1s) Bit: a 0 or 1 Byte: eight 0s and 1s in combination Computer CANNOT understand or store characters Each character in a string is represented by a number in binary using the ASCII Code ASCII Code : represent the 128 original characters and take up 1 byte of space in memory Special characters take up 2 bytes in memory

59 ASCII CODE

60 ASCII Code Needed to be consistent between all computer types Think of it as a secret language each character is represented by a number in binary When the computer encounters each letter, it translates the ASCII code value into its appropriate character

61 String comparison Equality Strings compared character by character, starting with the first character Comparing the ASCII code of each character in each string in order Two strings are equal if they are the same length AND if each index s characters are the same This means: Lowercase and uppercase characters of the same letter are DIFFERENT they have different ASCII Code values

62 String Comparison Inequality (<, >, <=, >=) When an inequality is used on strings, the computer compares ASCII Code values Will evaluate to TRUE or FALSE Ex: A < a TRUE Z < a TRUE hello < Hello FALSE 9 < A TRUE

63 ASCII CODES (Generalized) Symbols < Numbers < Upper Case < Lower Case

64 Practice For each statement below decide whether the statement is TRUE or FALSE! 1. Yellow == yellow 2. green <= Green 3. Bears < Packers 4. Packers!= packers 5. It is cold today > It is cool today 6.?What > What? 7. ABCD EFG < ABC DEFG 8. Hello == Hello

65 Practice For each statement below decide whether the statement is TRUE or FALSE! 1. Yellow == yellow FALSE 2. green <= Green FALSE 3. Bears < Packers TRUE 4. Packers!= packers TRUE 5. It is cold today > It is cool today FALSE 6.?What < What? TRUE 7. ABCD EFG < ABC DEFG FALSE 8. Hello == Hello FALSE

66 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L6AsciiCode

67 In Class Project Type the Following (Page 1 of 2) # ASCII Code # **Insert Today s Date Here** str1 = string #1 # declare and initialize string variable ascii0 = ord(str1[0]) # ASCII code for character at index 1 ascii1 = ord(str1[1]) # ASCII code for character at index 2 ascii2 = ord(str1[2]) # ASCII code for character at index 3

68 In Class Project Type the Following (Page 2 of 2) print( ascii0:, ascii0) print( ascii1:, ascii1) print( ascii2:, ascii2) # print first ASCII code value # print first ASCII code value # print first ASCII code value

69 Ordinal Function - Prediction What information does the ordinal function take in? What does the ordinal function do

70 ord(<single character>) The ordinal function takes in a single character (NOT an entire string) and outputs the ASCII code number (ordinal) associated with the character Examples: ord( a ) = 97 ord( A ) = 65 ord( <single character> ) **can also take in a string index (like example from our previous program)**

71 Character Function - Prediction Using your knowledge of the ordinal function, make a prediction on what the character function will do BEFORE we try it out What information does the character function take in? What does the character function do

72 In Class Project Add the following to the program started in: U5L6AsciiCode # character function experimentation exp1 = chr(77) # finds character with ASCII value 77 exp2 = chr(97) # finds character with ASCII value 97 exp3 = chr(116) # finds character with ASCII value116 exp4 = chr(104) # finds character with ASCII value 104 print(exp1, exp2, exp3, exp4)

73 chr(integer) The character function takes in an integer and outputs the character associated with that ASCII code number Examples: chr(65) = A chr(97) = a chr(integer)

74 Length Function - Prediction Using the name of the function make a prediction about what the length function does in Python What information does the length function take in? What does the length function do?

75 In Class Project Add the following to the program started in: U5L6AsciiCode # length function experimentation message = Hello, there! # creates string variable exp5 = len(message) # finds number of characters in # string called message exp6 = len( Hello! ) # find number of characters in # Hello! print(message, exp5) print( Hello!, exp 6) # prints message and num of chars # prints Hello! and num of chars

76 len( String ) The length function takes in a string and outputs the number of characters in the string Examples: len( HI ) = 2 len( String ) message = Hello, World! len(message) = 13

77 Practice on Your Own: ASCII Code of String Create a program that meets the following conditions: Takes in ANY string from a user. Print the ASCII Code for each character in the string in order. The ASCII codes should appear on one line. Example: Please enter a string: Math ASCII Code:

78 Homework None

79

80 DAY 4 Additional String Functions

81 I can.. Explain and use string functions to manipulate and use the various characteristics of strings.

82 What is we wanted to make yesterday s program in reverse? Let s write a program together that will take in a string of numbers (separated by a comma) and output the string of characters represented by the numbers

83 <string name>.split( <split character ) The dot split function will always be attached to a string, and will split the string at the character each time it appears The string will break up into segments, which will be saved as a list of items to be accessed. <string name>.split( <split character> ) Examples: message = He,llo, Wor,ld

84 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L7Split

85 In Class Project Type the Following (Page 1 of 1) # Split Function # **Insert Today s Date Here** messagetest = he,llo, wor,ld print(messagetest.split(, )) # string containing commas # splits the string # messagetest every time a # comma is found and prints # each segment (without the # comma) to the screen

86 <string name>.split() SPECIAL NOTE: If no split character is provided and the area inside the parentheses is blank, Python will, by default, split the string at each SPACE

87 Let s reverse yesterday s program using dot split!

88 In Class Project Type the Following (Page 1 of 2) # Split Function # **Insert Today s Date Here** messageascii = input( Please enter in a string of ASCII Code characters separated by a comma: ) # Note: this should all be on one line # input message for user to input ASCII code numbers message = # creates variable to hold string #represented by ASCII code numbers

89 In Class Project Type the Following (Page 2 of 2) # the code below takes the string messageascii and splits it # at every comma. The for loop takes each split chunk, # evaluates the number in the split chunk, turns the number # into its ASCII code character, and concatenates the # character with the message string for num in messageascii.split(, ) codenum = eval(num) message = message + chr(codenum) print(message) # prints the string of characters

90 String Methods Investigation There are many more strings functions to learn! After completing the string investigation you will understand 8 different string methods Once everyone is done, we will regroup and discuss as a class.capitalize().title().lower().replace(, ).count( ).upper().center(#).find( )

91 String Methods (pg. 1) <string name>.capitalize() returns a copy of the string with ONLY the first character capitalized Ex: message = hello Friend message.capitalize() Hello friend <string name>.lower() returns a copy of the string in all lowercase letters Ex: message = hello Friend message.lower() hello friend

92 String Methods (pg. 2) <string name>.upper() returns a copy of the string with all uppercase letters Ex: message = hello Friend message.upper() HELLO FRIEND <string name>.title() returns a copy of the string with the first letter in each word capitalized (title case) Ex: message = hello Friend message.title() Hello friend

93 String Methods (pg. 3) <string name>.count( substring ) counts the number of times a substring (or character) is found in a string and returns the number Ex: message = no I do not like snow message.count( no ) 3 <string name>.find( substring ) returns the FIRST position (index number) of the substring or character this will return a NUMBER Ex: message = I do not like snow message.find( no ) 5

94 String Methods (pg. 4) <string name>.center(integer) if placed inside a print statement, this function will center the string in a given width (integer provided) <string name>.replace( oldsub, newsub ) returns a string with the old substring replaced by the new substring Ex: message = no I do not like snow message.replace( no, yes) yes I do yest like syesw

95 Practice on Your Own: Vowels Program Create a program that meets the following conditions: Takes in ANY string from a user. Calculates the number of vowels in a string, regardless of the case (upper or lower)

96 Homework Worksheet 5C

97

98 DAY 5 Random Numbers

99 I can.. Use random numbers in Python.

100 Random Numbers Numbers that are generated randomly by the computer Used for games and simulations Used for uncertain situations Ex: the chance of flipping a coin heads up is 50% -- but this doesn t mean that every other flip is a head

101 Pseudo Random Numbers How random numbers are generated in Python Works by starting with a seed value This value is fed to the function to produce a random number The current value is then fed back in to produce a new number If you were to start this process over again with the same seed, you d get the same set of random numbers in a row

102 How is the seed determined? Python generates the initial seed value from the day and time when the module is loaded As a result, you get a different seed every time the program is run

103 Must import in random number functions Similar to the turtle graphics, random numbers must be imported into python The following line of code MUST be at the beginning of your program if random numbers are to be used from random import random and/or from random import randrange

104 Main functions for random 1. random() 2. randrange(<integer>, <integer>) 3. randrange(<integer>, <integer>, <integer>)

105 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L8Random

106 In Class Project Type the Following (Page 1 of 1) # Random Function # **Insert Today s Date Here** from random import random # import random functions for i in range(20): num1 = random() print(num1) # loops 20 times # random number generated # prints rand num to screen

107 random() Generates a random number between 0 and 1 0 is included in the set of numbers 1 is NOT included in the set of numbers Example x = random() 0 <= x < 1

108 In Class Project Add the following to your program(page 1 of 1) # add to type from random import randrange # import randrange print() # insert blank line for i in range(20): num2 = randrange(0,6) print(num2) # loops 20 times # generate rand num # prints rand num to screen

109 randrange(<integer>, <integer>) Generates a random integer number between the two integers The first integer is included in the set of numbers The second integer is NOT included in the set of numbers Examples x = randrange(4, 10) 4, 5, 6, 7, 8, 9 x = randrange(-2, 2) -2, -1, 0, 1

110 In Class Project Add the following to your program(page 1 of 1) # add to type from random import randrange # import randrange print() # insert blank line for i in range(20): # loops 20 times num3 = randrange(0,100, 5) # generate rand num print(num3) # prints rand num to screen

111 randrange(<integer>, <integer>, <integer>) Generates a random integer number between the first two integer, the third integer represents the number of counts between the randomly generated numbers The first integer is included in the set of numbers The second integer is NOT included in the set of numbers The third number represents the number of counts all randomly generated numbers will be apart Examples x = randrange(4, 10, 2) 4, 6, 8 x = randrange(3, 20, 5) 3, 8, 13, 18

112 Practice For each of the following, determine the set of random numbers 1) random() 2) randrange(5, 12) 3) randrange(-3, 0) 4) randrange(40, 100, 20) 5) randrange(5, 20, 4)

113 Practice For each of the following, determine the set of random numbers 1) random() 2) randrange(5, 12) 0 <= x < 1 5, 6, 7, 8, 9, 10, 11 *rand num between 0 and 1, 1 not included* 3) randrange(-3, 0) 4) randrange(10, 10, 90) -3, -2, -1 10, 20, 30, 40, 50, 60, 70, 80 5) randrange(5, 20, 4) 5, 9, 13, 17

114 Math with Random Numbers Let s look into what happens when we perform basic mathematical functions on the random number function Examples: random()*5 randrange(0, 5) + 1

115 Let s try it out in Python! Open up the Python IDLE File New File File Save As Name: U5L8RandomMath

116 In Class Project Type the Following (Page 1 of 1) # Random Math # **Insert Today s Date Here** from random import random from random import randrange # import random functions # import randrange functions for i in range(10): num1 = random()*5 print(num1) # loops 20 times # random number generated # prints rand num to screen

117 Describe in your own words What happened in the previous program when we multiplied the random() function by 5 random()*5

118 Make a prediction What do you think will happen when we multiple randrange() by 5? randrange(1, 6)*5

119 In Class Project Add the Following to your program (Page 1 of 1) print() # print blank line for i in range(10): # loops 20 times num2 = randrange(1, 6)*5 # random number generated print(num2) # prints rand num to screen

120 Multiplication with Random Numbers Generates the random number Then multiples the random number by the value Ex: random()*9 0 <= x < 9 **expands range up to 9** randrange(3, 7)*6 3*6, 4*6, 5*6, 6*6 18, 24, 30, 36

121 Now let s try addition Make predictions what will happen with the following: random() + 7 randrange(2, 7) + 10

122 In Class Project Add the Following to your program (Page 1 of 1) print() # print blank line for i in range(10): num3 = random() + 7 print(num3) print() # loops 20 times # random number generated # prints rand num to screen # print blank line for i in range(10): # loops 20 times num4 = randrange(2, 7) + 10 # rand num generated print(num4) # prints rand num to screen

123 Addition with Random Numbers Generates the random number Adds (or subtracts) the value from the number Ex: 9** random() <= x < 10 **moves range up to starting at randrange(2, 5) , 3+11, , 14, 15

124 Practice For each of the following, determine the set of random numbers 1) random()*6 4) random() ) random()* ) randrange(1, 7)*3 3) randrange(20, 24) + 5 6) randrange(15, 17)*4 + 8

125 Practice For each of the following, determine the set of random numbers 1) random()*6 2) random() <= x < 6 17 <= x < 18 3) random()* ) randrange(1, 7)*3 12 <= x < 15 3, 6, 9, 12, 15, 18 5) randrange(20, 24) + 5 6) randrange(1, 5)* , 26, 27 12, 16, 20, 24

126 Homework Worksheet 5D

127

Strings in Python 1 Midterm#1 Exam Review CS 8: Introduction to Computer Science Lecture #6

Strings in Python 1 Midterm#1 Exam Review CS 8: Introduction to Computer Science Lecture #6 Strings in Python 1 Midterm#1 Exam Review CS 8: Introduction to Computer Science Lecture #6 Ziad Matni Dept. of Computer Science, UCSB Administrative Turn in Homework #2 today Homework #3 is assigned and

More information

CS 115 Lecture 13. Strings. Neil Moore. Department of Computer Science University of Kentucky Lexington, Kentucky

CS 115 Lecture 13. Strings. Neil Moore. Department of Computer Science University of Kentucky Lexington, Kentucky CS 115 Lecture 13 Strings Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 29 October 2015 Strings We ve been using strings for a while. What can

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

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

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

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2016 Chapter 5 Part 1 Instructor: Long Ma The Department of Computer Science Objectives Chapter 5: Sequences: Strings, Lists, and Files

More information

Notes on Chapter 1 Variables and String

Notes on Chapter 1 Variables and String Notes on Chapter 1 Variables and String Note 0: There are two things in Python; variables which can hold data and the data itself. The data itself consists of different kinds of data. These include numbers,

More information

Midterm 1 Review. Important control structures. Important things to review. Functions Loops Conditionals

Midterm 1 Review. Important control structures. Important things to review. Functions Loops Conditionals Midterm 1 Review Important control structures Functions Loops Conditionals Important things to review Binary numbers Boolean operators (and, or, not) String operations: len, ord, +, *, slice, index List

More information

Program Planning, Data Comparisons, Strings

Program Planning, Data Comparisons, Strings Program Planning, Data Comparisons, Strings Program Planning Data Comparisons Strings Reading for this class: Dawson, Chapter 3 (p. 80 to end) and 4 Program Planning When you write your first programs,

More information

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

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

More information

Computing with Numbers

Computing with Numbers Computing with Numbers Example output: Numeric Data Types Numeric Data Types Whole numbers are represented using the integer data type (int for short).values of type int can be positive or negative whole

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Lecture 1. Types, Expressions, & Variables

Lecture 1. Types, Expressions, & Variables Lecture 1 Types, Expressions, & Variables About Your Instructor Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/29/13 Overview, Types & Expressions 2 Helping

More information

Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110. Lecture 2 Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2015 Chapter 5 Part 1 The Department of Computer Science Objectives To understand the string data type and how strings are represented

More information

Lecture 3. Input, Output and Data Types

Lecture 3. Input, Output and Data Types Lecture 3 Input, Output and Data Types Goals for today Variable Types Integers, Floating-Point, Strings, Booleans Conversion between types Operations on types Input/Output Some ways of getting input, and

More information

Decisions, Decisions. Testing, testing C H A P T E R 7

Decisions, Decisions. Testing, testing C H A P T E R 7 C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little

More information

Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords

Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords Worksheet 1: Introductory Exercises Turtle Programming Calculations The Print Function Comments Syntax Semantics Strings Concatenation Quotation Marks Types Variables Restrictions on Variable Names Long

More information

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below. Name: Date: Instructions: PYTHON - INTRODUCTORY TASKS Open Idle (the program we will be using to write our Python codes). We can use the following code in Python to work out numeracy calculations. Try

More information

Introduction to Programming in Turing. Input, Output, and Variables

Introduction to Programming in Turing. Input, Output, and Variables Introduction to Programming in Turing Input, Output, and Variables The IPO Model The most basic model for a computer system is the Input-Processing-Output (IPO) Model. In order to interact with the computer

More information

Programming in Python

Programming in Python 3. Sequences: Strings, Tuples, Lists 15.10.2009 Comments and hello.py hello.py # Our code examples are starting to get larger. # I will display "real" programs like this, not as a # dialog with the Python

More information

Strings, Lists, and Sequences

Strings, Lists, and Sequences Strings, Lists, and Sequences It turns out that strings are really a special kind of sequence, so these operations also apply to sequences! >>> [1,2] + [3,4] [1, 2, 3, 4] >>> [1,2]*3 [1, 2, 1, 2, 1, 2]

More information

Slicing. Open pizza_slicer.py

Slicing. Open pizza_slicer.py Slicing and Tuples Slicing Open pizza_slicer.py Indexing a string is a great way of getting to a single value in a string However, what if you want to use a section of a string Like the middle name of

More information

More about Loops and Decisions

More about Loops and Decisions More about Loops and Decisions 5 In this chapter, we continue to explore the topic of repetition structures. We will discuss how loops are used in conjunction with the other control structures sequence

More information

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2 Python for Analytics Python Fundamentals RSI Chapters 1 and 2 Learning Objectives Theory: You should be able to explain... General programming terms like source code, interpreter, compiler, object code,

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents 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

More information

CS2304: Python for Java Programmers. CS2304: Sequences and Collections

CS2304: Python for Java Programmers. CS2304: Sequences and Collections CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for

More information

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

Introduction to String Manipulation

Introduction to String Manipulation Introduction to Computer Programming Introduction to String Manipulation CSCI-UA.0002 What is a String? A String is a data type in the Python programming language A String can be described as a "sequence

More information

Chapter 10: Creating and Modifying Text Lists Modules

Chapter 10: Creating and Modifying Text Lists Modules Chapter 10: Creating and Modifying Text Lists Modules Text Text is manipulated as strings A string is a sequence of characters, stored in memory as an array H e l l o 0 1 2 3 4 Strings Strings are defined

More information

Basic data types. Building blocks of computation

Basic data types. Building blocks of computation Basic data types Building blocks of computation Goals By the end of this lesson you will be able to: Understand the commonly used basic data types of C++ including Characters Integers Floating-point values

More information

Language Reference Manual

Language Reference Manual ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents

More information

CSCA20 Worksheet Strings

CSCA20 Worksheet Strings 1 Introduction to strings CSCA20 Worksheet Strings A string is just a sequence of characters. Why do you think it is called string? List some real life applications that use strings: 2 Basics We define

More information

Introduction to Programming EC-105. Lecture 2

Introduction to Programming EC-105. Lecture 2 Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically

More information

Today s topics. Announcements/Reminders: Characters and strings Review of topics for Test 1

Today s topics. Announcements/Reminders: Characters and strings Review of topics for Test 1 Today s topics Characters and strings Review of topics for Test 1 Announcements/Reminders: Assignment 1b due tonight 11:59pm Test 1 in class on Thursday Characters & strings We have used strings already:

More information

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018 Python Input, output and variables Lecture 23 COMPSCI111/111G SS 2018 1 Today s lecture What is Python? Displaying text on screen using print() Variables Numbers and basic arithmetic Getting input from

More information

Accounts and Passwords

Accounts and Passwords Accounts and Passwords Hello, I m Kate and we re here to learn how to set up an account on a website. Many websites allow you to create a personal account. Your account will have its own username and password.

More information

Python Day 3 11/28/16

Python Day 3 11/28/16 Python Day 3 11/28/16 Objectives Review Concepts Types of Errors Escape sequences String functions Find the Errors bookcost = int(input("how much is the book: ")) discount = float(input("what is the discount:

More information

Introduction to Python. Data Structures

Introduction to Python. Data Structures Introduction to Python Data Structures Data Structures Encapsulation & Notion of an Object Data + a set of methods (functions) that operate on the data A.foo() Linear Data Structure: List, Strings, sequences

More information

ENGR 101 Engineering Design Workshop

ENGR 101 Engineering Design Workshop ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as

More information

Programming with Python

Programming with Python Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2

More information

Working with Strings. Husni. "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc.

Working with Strings. Husni. The Practice of Computing Using Python, Punch & Enbody, Copyright 2013 Pearson Education, Inc. Working with Strings Husni "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc. Sequence of characters We've talked about strings being a sequence of characters.

More information

Haskell Programs. Haskell Fundamentals. What are Types? Some Very Basic Types. Types are very important in Haskell:

Haskell Programs. Haskell Fundamentals. What are Types? Some Very Basic Types. Types are very important in Haskell: Haskell Programs We re covering material from Chapters 1-2 (and maybe 3) of the textbook. Haskell Fundamentals Prof. Susan Older A Haskell program is a series of comments and definitions. Each comment

More information

Variables, Constants, and Data Types

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

More information

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 23 Introduction to Arduino- II Hi. Now, we will continue

More information

CMSC201 Computer Science I for Majors

CMSC201 Computer Science I for Majors CMSC201 Computer Science I for Majors Lecture 09 For Loops All materials copyright UMBC unless otherwise noted Last Class We Covered Lists and what they are used for Operations a list can perform Including

More information

Full file at

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

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Sequence of Characters. Non-printing Characters. And Then There Is """ """ Subset of UTF-8. String Representation 6/5/2018.

Sequence of Characters. Non-printing Characters. And Then There Is   Subset of UTF-8. String Representation 6/5/2018. Chapter 4 Working with Strings Sequence of Characters we've talked about strings being a sequence of characters. a string is indicated between ' ' or " " the exact sequence of characters is maintained

More information

The Practice of Computing Using PYTHON. Chapter 4. Working with Strings. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

The Practice of Computing Using PYTHON. Chapter 4. Working with Strings. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 4 Working with Strings 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Sequence of Characters We

More information

COLLEGE OF ENGINEERING, NASHIK-4

COLLEGE OF ENGINEERING, NASHIK-4 Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK-4 DEPARTMENT OF COMPUTER ENGINEERING Important PYTHON Questions 1. What is Python? Python is a high-level, interpreted, interactive and object-oriented

More information

Python 1: Intro! Max Dougherty Andrew Schmitt

Python 1: Intro! Max Dougherty Andrew Schmitt Python 1: Intro! Max Dougherty Andrew Schmitt Computational Thinking Two factors of programming: The conceptual solution to a problem. Solution syntax in a programming language BJC tries to isolate and

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

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

\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

More information

Sequences: Strings, Lists, and Files

Sequences: Strings, Lists, and Files Sequences: Strings, Lists, and Files Read: Chapter 5, Sections 11.1-11.3 from Chapter 11 in the textbook Strings: So far we have examined in depth two numerical types of data: integers (int) and floating

More information

Introduction to Python

Introduction to Python Introduction to Python Why is Python? Object-oriented Free (open source) Portable Powerful Mixable Easy to use Easy to learn Running Python Immediate mode Script mode Integrated Development Environment

More information

Math Day 2 Programming: How to make computers do math for you

Math Day 2 Programming: How to make computers do math for you Math Day 2 Programming: How to make computers do math for you Matt Coles February 10, 2015 1 Intro to Python (15min) Python is an example of a programming language. There are many programming languages.

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have

More information

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

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

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Real Python: Python 3 Cheat Sheet

Real Python: Python 3 Cheat Sheet Real Python: Python 3 Cheat Sheet Numbers....................................... 3 Strings........................................ 5 Booleans....................................... 7 Lists.........................................

More information

MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON

MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON Table of contents 2 1. Learning Outcomes 2. Introduction 3. The first program: hello world! 4. The second program: hello (your name)! 5. More data types 6.

More information

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review StudyHub+ 1 StudyHub: AP Java Semester One Final Review StudyHub+ 2 Terminology: Primitive Data Type: Most basic data types in the Java language. The eight primitive data types are: Char: A single character

More information

Variable and Data Type I

Variable and Data Type I Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store

More information

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

PYTHON MOCK TEST PYTHON MOCK TEST III

PYTHON MOCK TEST PYTHON MOCK TEST III http://www.tutorialspoint.com PYTHON MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Python. You can download these sample mock tests at your local

More information

Programming Fundamentals and Python

Programming Fundamentals and Python Chapter 2 Programming Fundamentals and Python This chapter provides a non-technical overview of Python and will cover the basic programming knowledge needed for the rest of the chapters in Part 1. It contains

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

More information

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT Python The way of a program Srinidhi H Asst Professor Dept of CSE, MSRIT 1 Problem Solving Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

CS 102 Lab 3 Fall 2012

CS 102 Lab 3 Fall 2012 Name: The symbol marks programming exercises. Upon completion, always capture a screenshot and include it in your lab report. Email lab report to instructor at the end of the lab. Review of built-in functions

More information

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

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,

More information

ISE 101 Introduction to Information Systems. Lecture 3 Objectives: While loops Strings

ISE 101 Introduction to Information Systems. Lecture 3 Objectives: While loops Strings ISE 101 Introduction to Information Systems Lecture 3 Objectives: While loops Strings While Loops Write a Python script that computes the sum of squares from 1 to 5. sum = 0; sum = sum + 1**2; sum = sum

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Computing with Strings. Learning Outcomes. Python s String Type 9/23/2012

Computing with Strings. Learning Outcomes. Python s String Type 9/23/2012 Computing with Strings CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17 1 Learning Outcomes To understand the string data type and how strings are represented

More information

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming. OPERATORS This tutorial will teach you about operators. s are symbols that are used to represent an actions used in programming. Here is the link to the tutorial on TouchDevelop: http://tdev.ly/qwausldq

More information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

More information

Perl for Biologists. Session 2 March 19, Constants, variables and functions. Jaroslaw Pillardy

Perl for Biologists. Session 2 March 19, Constants, variables and functions. Jaroslaw Pillardy Perl for Biologists Session 2 March 19, 2014 Constants, variables and functions Jaroslaw Pillardy Session 2: Constants, variables and functions Perl for Biologists 1.1 1 "shebang" notation path to the

More information

Python Input, output and variables

Python Input, output and variables Today s lecture Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016! What is Python?! Displaying text on screen using print()! Variables! Numbers and basic arithmetic! Getting input from

More information

Introduction to programming with Python

Introduction to programming with Python Introduction to programming with Python Ing. Lelio Campanile 1/61 Main Goal - Introduce you to programming - introduce you to the most essential feature of python programming 2/61 Before to start The name

More information

4. Java language basics: Function. Minhaeng Lee

4. Java language basics: Function. Minhaeng Lee 4. Java language basics: Function Minhaeng Lee Review : loop Program print from 20 to 10 (reverse order) While/for Program print from 1, 3, 5, 7.. 21 (two interval) Make a condition that make true only

More information

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an  . Michigan State University CSE 231, Fall 2013 CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?

More information

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016 Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016 Today s lecture u What is Python? u Displaying text on screen using print() u Variables u Numbers and basic arithmetic u Getting input

More information

A variable is a name for a location in memory A variable must be declared

A variable is a name for a location in memory A variable must be declared Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

More information

CMSC201 Computer Science I for Majors

CMSC201 Computer Science I for Majors CMSC201 Computer Science I for Majors Lecture 09 Strings Last Class We Covered Lists and what they are used for Getting the length of a list Operations like append() and remove() Iterating over a list

More information

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi CMPT 120 Basics of Python Summer 2012 Instructor: Hassan Khosravi Python A simple programming language to implement your ideas Design philosophy emphasizes code readability Implementation of Python was

More information

Datatypes, Variables, and Operations

Datatypes, Variables, and Operations Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

More information

CS1 Lecture 3 Jan. 22, 2018

CS1 Lecture 3 Jan. 22, 2018 CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow

More information

Topic 7: Lists, Dictionaries and Strings

Topic 7: Lists, Dictionaries and Strings Topic 7: Lists, Dictionaries and Strings The human animal differs from the lesser primates in his passion for lists of Ten Best H. Allen Smith 1 Textbook Strongly Recommended Exercises The Python Workbook:

More information

Sequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python

Sequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python Python Sequence Types Sequence types str and bytes are sequence types Sequence types have several operations defined for them Indexing Python Sequence Types Each element in a sequence can be extracted

More information

Building on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements

Building on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements Chapter 5 Looping Building on the foundation Now that we know a little about cout cin math operators boolean operators making decisions using if statements Advantages of Computers Computers are really

More information

Chapter 10: Strings and Hashtables

Chapter 10: Strings and Hashtables Chapter 10: Strings and Hashtables This chapter describes the string and hashtable data types in detail. Strings hold text-- words and phrases-- and are used in all applications with natural language processing.

More information

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops PRG PROGRAMMING ESSENTIALS 1 Lecture 2 Program flow, Conditionals, Loops https://cw.fel.cvut.cz/wiki/courses/be5b33prg/start Michal Reinštein Czech Technical University in Prague, Faculty of Electrical

More information

Play with Python: An intro to Data Science

Play with Python: An intro to Data Science Play with Python: An intro to Data Science Ignacio Larrú Instituto de Empresa Who am I? Passionate about Technology From Iphone apps to algorithmic programming I love innovative technology Former Entrepreneur:

More information

String and list processing

String and list processing String and list processing Michael Mandel Lecture 3 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture03final.ipynb

More information

1 Strings (Review) CS151: Problem Solving and Programming

1 Strings (Review) CS151: Problem Solving and Programming 1 Strings (Review) Strings are a collection of characters. quotes. this is a string "this is also a string" In python, strings can be delineated by either single or double If you use one type of quote

More information

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

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

More information

Chapter 4: Conditionals and Loops

Chapter 4: Conditionals and Loops Chapter 4: Conditionals and Loops CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 4: Conditionals and Loops CS 121 1 / 69 Chapter 4 Topics Flow

More information

Beyond Blocks: Python Session #1

Beyond Blocks: Python Session #1 Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

More information