String Basics¶
-
Assume two variables,
last_name
andfirst_name
, have been defined and refer to strings. Write an assignment statement to make a new string,name
, that is the concatenation offirst_name
andlast_name
with a space between.Remember that you use+
to concatenate strings. Remember that you have to put a space between the first and last names.
-
Assume two variables,
last_name
andfirst_name
, have been defined and refer to strings. Write an assignment statement to make a new string,name
, that is the concatenation of the first initial offirst_name
andlast_name
with a space between.The first character in a string is accessed by indexing at 0. E.g.,
greeting = ‘hello’
firstLetter = greeting[0]
-
Write a two-line program to read in a string from the user and then print out the length of that string.Use len(theString) to get the length of the string.
-
Write a small program that asks the user for a string and then prints out the first and last characters of that string. E.g.,
Enter a string:
Hello, world
First and last characters are: H d
Use -1 as the index to get the last character of the string.