aDa LoVeLaCe

[vocab] variable | method

M. Lim
Intro to Programming
3 min readJan 17, 2018

--

→ Lab Assignment: “Changing Case (Methods)” on repl.it

[python learned]

  • how to define a variable
  • .swapcase() method
  • .title() method
  • .upper() method
  • .lower() method

Using variables & methods

1. Search for “IDLE” in the Start Menu & click to open it.

IDLE is a development environment for Python. It has two main window types, the Shell window and the Editor window. For this example, we will be using the Shell window:

  • >>> These three arrows are called the prompt. The prompt automatically appears when the shell is ready to accept commands.

2. Run each line below, one at a time. Press Enter/Return to run each line after typing it.

Remember: You don’t need to type >>> (the prompt)

  1. The first line creates a variable. A variable is used to store information (data) so it can be easily used and referenced later. In this case, our variable’s name is name and it contains the string "aDa LoVeLaCe".
  2. The second line applies the .swapcase() method to name. A method is a function that acts on a specific object — in this case, name. What does the .swapcase() method do to name?

Why use variables?

Variables allow you to use the same value in many places, making it easier to to change the value later. Now if you want to change the value, you only need to do it in one place.

Naming variables

Variable names cannot:

  • have spaces
  • start with a number
  • contain symbols other than _ (underscore)

Variable names should not:

  • be the same as an existing function or keyword (such as print), because that gets confusing
  • start with a capital letter, because that’s reserved for another data type (called “classes,” which we’ll learn about later)

If a variable name has multiple words, it can be written in “camel case” or “snake case”:

Ada Lovelace, from The Thrilling Adventures of Lovelace and Babbage: The (Mostly) True Story of the First Computer, a graphic novel.

--

--