Docsity

CSci 127 Lecture 3: Strings, Indexing, Substrings, Arithmetic, Study notes of Chemistry

Partial preview of the text

Download CSci 127 Lecture 3: Strings, Indexing, Substrings, Arithmetic and more Study notes Chemistry in PDF only on Docsity!

CSci 127: Introduction to Computer

Science

hunter.cuny.edu/ csci

Today’s Topics

More on

Strings

Arithmetic

Indexing and Slicing Lists

Colors & Hexadecimal

Notation

Substrings

s =

"FridaysSaturdaysSundays"

days = s[7]

days = s[7:15]

days = s[:-1]

Strings are made up

of individual

characters (letters,

numbers, etc.)

Substrings

s =

"FridaysSaturdaysSundays"

days = s[7]

days = s[7:15]

days = s[:-1]

Strings are made up

of individual

characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an individual location or a “substring” of the string.

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an 0 individual 1 2 3 4 location 5 6 or 7 a 8 “substring” ... 16 17 of 18 the 19 string. 20 21 22

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[0] is

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an 0 individual 1 2 3 4 location 5 6 or 7 a 8 “substring” ... 16 17 of 18 the 19 string. 20 21 22

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[0] is "F".

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an individual location or a “substring” of the string.

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[1] is "r".

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an individual location or a “substring” of the string.

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[-1] is

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an individual location or a “substring” of the string.

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[3:6] is

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an individual location or a “substring” of the string.

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[3:6] is "day".

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an individual location or a “substring” of the string.

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[:3] is "Fri".

Substrings

s = "FridaysSaturdaysSundays"

Strings are made up of individual characters (letters,

numbers, etc.)

Useful to be able to refer to pieces of a string, either

an individual location or a “substring” of the string.

F r i d a y s S a ... S u n d a y s ... - 4 - 3 - 2 - 1

s[:-1] is

Today’s Topics

More on Strings

Arithmetic

Indexing and Slicing Lists

Colors & Hexadecimal

Notation

Arithmet

ic

Some arithmetic operators in

Python: Addition: