Game Development Reference
In-Depth Information
Hello world!
What is your name?
poop
It is good to meet you, poop
Variable Names
The computer doesn't care what you name your variables, but you should. Giving
variables names that reflect what type of data they contain makes it easier to understand
what a program does. Instead of name , we could have called this variable
abrahamLincoln or nAmE . The computer will run the program the same (as long as you
consistently use abrahamLincoln or nAmE ).
Variable names (as well as everything else in Python) are case-sensitive. Case-
sensitive means the same variable name in a different case is considered to be an entirely
separate variable name. So spam , SPAM , Spam , and sPAM are considered to be four
different variables in Python. They each can contain their own separate values.
It's a bad idea to have differently-cased variables in your program. If you stored your
first name in the variable name and your last name in the variable NAME , it would be very
confusing when you read your code weeks after you first wrote it. Did name mean first and
NAME mean last, or the other way around?
If you accidentally switch the name and NAME variables, then your program will still
run (that is, it won't have any syntax errors) but it will run incorrectly. This type of flaw in
your code is called a bug . It is very common to accidentally make bugs in your programs
while you write them. This is why it is important that the variable names you choose make
sense.
It also helps to capitalize variable names if they include more than one word. If you store
a string of what you had for breakfast in a variable, the variable name
whatIHadForBreakfastThisMorning is much easier to read than
whatihadforbreakfastthismorning . This is a convention (that is, an optional
but standard way of doing things) in Python programming. (Although even better would be
something simple, like todaysBreakfast . Capitalizing the first letter of each word in
variable names makes the program more readable.
Summary
Now that we have learned how to deal with text, we can start making programs that the
user can run and interact with. This is important because text is the main way the user and
the computer will communicate with each other. The player will enter text to the program
through the keyboard with the input() function. And the computer will display text on
 
Search WWH ::




Custom Search