-
Notifications
You must be signed in to change notification settings - Fork 30
Singlechar
alecgoebel edited this page Feb 3, 2012
·
1 revision
You should use descriptive names as a rule, but sometimes that is just too much for a temporary variable. Also, you may come across a bunch of single letter variables when looking at other code. Here are some of them.
- i,j: used as counters in for loops to represent the step
for i in range(10):
print i- c: used as a manually updated counter
c = 0
while c < 20:
...
c += 1- c: also used to represent a single character
- s: an arbitrary string
- n,x: arbitrary numbers
- t: generic temporary variable, usually when swapping values
t = a
a = b
b = t- t: used for storing a total
t = 0
for n in values:
t += n- l, ll: an arbitrary list. l can also be an element of an arbitrary list
for l in ll:
print l- a,b: two similar values. Usually used when comparing two things
if a < b:
print a, "is less"- f: a generic file
f = open("info.txt")- k, v: generic keys and values. Only used when it really doesn't matter what the key or value are
# dct is a given dictionary
new_dct = {}
for k,v in dct.items():
new_dct[k] = v
# usually do this (generic people object...)
for id, info in people.items():
print id, info.name, info.age- m, n: when you need two generic numbers
-
o: an object. Aslo abbreviated as
obj -
a, kw: arguments and keyword arguments. Also abbreviated as
args, kwargs - r, c: row and column
Be sure to check out some of these other game programming and pygame variables