String Basics

  1. Assume two variables, last_name and first_name, have been defined and refer to strings. Write an assignment statement to make a new string, name, that is the concatenation of first_name and last_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.
  1. Assume two variables, last_name and first_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 of first_name and last_name with a space between.

    The first character in a string is accessed by indexing at 0. E.g.,

    greeting = ‘hello’

    firstLetter = greeting[0]

  1. 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.
  1. 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.
Next Section - List Basics