PyCon handout: Difference between revisions

no edit summary
imported>Jesstess
No edit summary
imported>Jesstess
No edit summary
 
Line 40:
 
<pre>
>>> print ("Hello")
'Hello'
>>> print ("Python, I'm your #1 fan!")
"Python, I'm your #1 fan!"
</pre>
Line 51:
 
<pre>
>>> print ("Hello" + "World")
'HelloWorld'
</pre>
Line 57:
<pre>
>>> name = "Jessica"
>>> print ("Hello " + name)
'Hello Jessica'
</pre>
Line 67:
 
<pre>
>>> print (len("Hello"))
4
>>> print (len(""))
0
>>> fish = "humuhumunukunukuapuaʻa"
>>> length = str(len(fish))
>>> print (fish + " is a Hawaiian fish whose name is " + length + " characters long.")
</pre>
 
Line 81:
 
<pre>
>>> print ('Hello')
'Hello'
>>> print ("Hello")
'Hello'
</pre>
Line 90:
 
<pre>
>>> print ("I'm a happy camper")
"I'm a happy campter"
</pre>
Line 97:
 
<pre>
>>> print ("A" * 40)
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>>> print "ABC" * 12
Line 103:
>>> h = "Happy"
>>> b = "Birthday"
>>> print ((h + b) * 10)
HappyBirthdayHappyBirthdayHappyBirthdayHappyBirthdayHappyBirthdayHappyBirthdayHappyBirthdayHappyBirthdayHappyBirthdayHappyBirthday
</pre>
Line 163:
<pre>
>>> if "banana" in "bananarama":
... print ("I miss the 80s.")
...
'I miss the 80s.'
Line 176:
>>> brother_age = 12
>>> if sister_age > brother_age:
... print ("sister is older")
... else:
... print ("brother is older")
...
sister is older
Line 207:
>>> temperature = 32
>>> if temperature > 60 and temperature < 75:
... print ("It's nice and cozy in here!")
... else:
... print ("Too extreme for me.")
...
Too extreme for me.
Line 217:
>>> hour = 11
>>> if hour < 7 or hour > 23:
... print ("Go away!")
... print ("I'm sleeping!")
... else:
... print ("Welcome to the cheese shop!")
... print ("Can I interest you in some choice gouda?")
...
Welcome to the cheese shop!
Line 238:
>>> brother_age = 12
>>> if sister_age > brother_age:
... print ("sister is older")
... elif sister_age == brother_age:
... print ("sister and brother are the same age")
... else:
... print ("brother is older")
...
sister is older
Line 254:
>>> color = "orange"
>>> if color == "green" or color == "red":
... print ("Christmas color!")
... elif color == "black" or color == "orange":
... print ("Halloween color!")
... elif color == "pink":
... print ("Valentine's Day color!")
...
Halloween color!
Line 392:
>>> names = ["Jessica", "Adam", "Liz"]
>>> for name in names:
... print (name)
...
Jessica
Line 401:
>>> names = ["Jessica", "Adam", "Liz"]
>>> for name in names:
... print ("Hello " + name)
...
Hello Jessica
Line 414:
>>> for name in ["Alice", "Bob", "Cassie", "Deb", "Ellen"]:
... if name[0] in "AEIOU":
... print (name + " starts with a vowel.")
...
Alice starts with a vowel.
Line 427:
... vowel_names.append(name)
...
>>> print (vowel_names)
['Alice', 'Ellen']</pre>
 
Line 439:
>>> for letter in letters:
... for number in numbers:
... print (letter * number)
...
a
Line 456:
>>> for number in numbers:
... for letter in letters:
... print (number * letter)
...
a
Anonymous user