String Data Type
String Data Type
Creating a string
A string is created by enclosing text in
quotes.
Getting string Input from user
when getting numerical input we use an
eval statement with the input
statement,
For example:
Challenge
Write a program that accepts a name from
the user and checks if there is a letter ‘e’ or
‘i’ in the name. It should print accordingly.
Solution
Combining in and not
E.g. to tell if a string does not contain
something:
Indexing
Picking out individual characters from a
string.
E.g. s='abcdefghij'.
Looping
scanning through a string one character
at a time.
Solution
String methods
Strings come with a ton of methods.
e.g.
Task
1. Write a program that asks the user for
a string and prints out the index of
each 'a‘ in the string.
Solution
2. Write a program that asks the user for
a string and creates a new string that
doubles each character of the original
string. For instance, if the user enters
Hello, the output should be HHeelllloo.
Solution