wikibooks Python 1 Flashcards
print “hello world”
print (‘hello world’)
Variable definition
something that holds a value that can change
Variable in which red is equal to 5
red = 5
Variable in which blue equals 10
blue = 10
Program which runs with the variables red and blue based on previous variable assignment placing red and then blue
print (red, blue)
5 10
Name of Variable location
left of equals sign
Value of Variable location
right of equals sign
String definition
a list of characters in order
Three ways to declare a string
Single quotes (‘) Double quotes (“) Triple quotes (“””)
Escaping the symbol definition
Placing a backslash before a symbol to show that the symbol should be included in the string
Escaping a quotation mark example
print»_space;> (“So I said, \”You don’t know me! You’ll never understand me!\””)
Concatenation operator
+
Concatenation example
> > > print (“Hello, “ + “world!”)
Hello, world!
Repeat strings operator
*
Repeat strings example
> > > print (“bouncy, “ * 3)
bouncy, bouncy, bouncy,
Function which finds the length of a string
len()
Finding string length example
> > > print (len(“Hello, world!”))
13
Function that turns a string into an integer
int()
Function that turns an integer into a string
str()
Function which outputs the information to the user
print()
Function which asks the user for a response and returns that response
input()
Are variables case-sensitive?
yes
Can spaces be substituted for tabs?
no
Object definition
aggregations of code and data which typically represent the pieces in a conceptual model of a system