Editing DS4UX (Spring 2016)/Day 3 lecture
From CommunityData
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 84: | Line 84: | ||
-1 | -1 | ||
===Strings=== | |||
==== Strings are a lot like lists==== | |||
== | >>> my_string = "Hello World" | ||
>>> my_string[0] | |||
=== | 'H' | ||
>>> my_string[:5] | |||
'Hello' | |||
>>> my_string[6:] | |||
'World' | |||
>>> my_string = my_string[:6] + "Jessica" | |||
>>> my_string | |||
'Hello Jessica' | |||
>>> 'H' in my_string | |||
True | |||
==== Formatting strings ==== | ==== Formatting strings ==== | ||
>>> x = 1 | >>> x = 1 | ||
>>> y = 1.234 | >>> y = 1.234 | ||
Line 98: | Line 106: | ||
>>> w = "elevator" | >>> w = "elevator" | ||
>>> all_together_now = "You can put ints like %d, floating point numbers like %f, boolean values like %s, and other strings like %s into a string without changing them to strings first!" % (x,y,z,w) | >>> all_together_now = "You can put ints like %d, floating point numbers like %f, boolean values like %s, and other strings like %s into a string without changing them to strings first!" % (x,y,z,w) | ||
==== Dealing with whitespace ==== | ==== Dealing with whitespace ==== | ||
Line 109: | Line 116: | ||
'this is a text string with lots of extra spaces' | 'this is a text string with lots of extra spaces' | ||
== New concepts for Week 3 exercises and challenges == | |||
==== Tuples ==== | ==== Tuples ==== | ||
Line 136: | Line 144: | ||
[0, 1, 2, 3, 4] | [0, 1, 2, 3, 4] | ||
>>> for i in range(5): | >>> for i in range(5): | ||
... print | ... print "Hi" * i | ||
... | ... | ||
Line 200: | Line 208: | ||
>>> for i in range(100): | >>> for i in range(100): | ||
... my_input = input("Please type something> ") | ... my_input = input("Please type something> ") | ||
... if | ... if input == "Quit": | ||
... print("Goodbye!") | ... print("Goodbye!") | ||
... break | ... break |