Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Strings in depth
Description: - strings in limitations - viewing characters

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


Delwin Thermitus
Cyber Security

Strings In Depth
-

Strings in limitations and viewing characters

String Limitation
- Strings have no size
- You can think of them as a series of characters
- The position of a character with in a string is known as an index
o ‘Hello’ H-e-l-l-o
o Index 0-1-2-3-4
Viewing Characters
- To View Characters at a particular index we use bracket notation([ ])
- Inside of that bracket notation we place the index of the string we’d like to see
▪ ‘Hello’ H-e-l-l-o
▪ Index 0-1-2-3-4
▪ S = ‘Hello’
▪ Print (s[0]) # ‘h’
Slicing Strings
-

To look at one character of a string we simply provide the index we would like to see
To look at multiple characters we can use the following syntax [start:end]
The starting index is inclusive while the end index is exclusive

‘Hello’
H-E-L-L-O
Index
0-1-2-3-4
S = ‘Hello’
-

Print (s[0:2]) # ‘HE’ – Start from 0 stop before 2
Print (s[1:] # ‘ello’ – start from 1, go to end
Print (s[1:-1]) # ‘ELL’ – Start from 1 stop 1 behind end

Len Function
- Len is used on any inerrable type to determinate the length
S = ‘Hello’
Length_s = len(s)
Print(length_s) #5

String Methods
- Methods are functions that are built in to specify types in python
- Source of these methods will be important to us to get familiar with but there are many
more than we will cover here
- String Methods do not have the ability to modify strings value because strings are non mutative


...
upper()
- S = ‘hElLo’
- S_Lower = S
...
upper() # ‘HELLO’

...
endwith(x)
- S = ‘this is so cool’
- Print(s
...
endswith(‘Kaia’))

-

#True
#false


...
find(‘is’) #2
Idx_of_x = s
...
replace(substr, new_substr) provide a substr to replace and what to replace it with
...
split(delimiter)
- provide a marker with in the string to break string repeatedly into a list
- s = ‘you are cool’
- list_of_words = s
Title: Strings in depth
Description: - strings in limitations - viewing characters