Python Flashcards
variable
name for something so you can use the name rather than the something as you code.
ex.
cars = 100
print “There are”, cars, “cars available.”
string
” (double-quotes) or ‘ (single-quotes) around text.
ex.
print “Let’s talk about coding.”
format string
Putting a variable inside a string.
ex.
my_name = ‘Wealth Coding”
print “Let’s talk about %s.” % my_name
print “I said %r is better than %r.” % (jordan, kobe)
format character
% (percent) followed by the variable.
ex.
%d, %r, %s
\n (back-slash n)
Go to next line.
””” (3 double-quotes)
Print text on multiple lines
ex. print """ I want to print on multiple lines so I will. """
escape sequences
\n go to the next line. \\ just one back slash. \t tab \t* indent and asterisk "I am 6'1\" tall" # escape double-quote 'I am 6\'1" tall.' escape singe=quote
raw_input()
How to get user to enter information.
ex.
print “How old are you?,
age = raw_input()
print “So, you’re %r old.” % age
raw input with a prompt
ex.
age = raw_input(“How old are you? “)
print “So, you’re %r old.” % age
script
another name for .py files
argument
When you type python ex13.py in terminal, ex13.py is the argument.
modules
features you import to make Python do more (also called libraries).
ex.
from sys import argv
argv
argument variable. This variable holds the arguments you pass to your Python script when you run it.
ex. from sys import argv
script, first, second = argv
print “The first variable is:”, first
unpack
“Take whatever is in argv (or something else), unpack it, and assign it to all of these variables on the left in that order.
ex.
script, first, second, third = argv
raw_input(prompt)
something like > prompt to get input from user. Similar to Zork or Adventure.
prompt = ‘> ‘
print “What do you like %s?” % user_name
likes = raw_input(prompt)