Friday, December 5, 2014

1.3.6 Guess a Letter


Conclusion 
1. Consider a string, tuple, and list of characters.
In []: a = 'acbde'
In []: b = ('a', 'b', 'c', 'd', 'e')
In []: c = ['a', 'b', 'c', 'd', 'e']
The values of a[3], b[3], and c[3] are all the same. In what ways are a, b, and c different? 
A string is just a word, letter, or sentence. A list/tuple can be the same thing but it's all divided into individual strings. Tuples are a fixed size, while lists are much more dynamic. You can't add or remove elements of a tuple, but you can with a list.
2.  Why do computer programming languages almost always have a variety of variable types? 
 They have a variety of types so that they can be more efficient under different circumstances. For example Boolean logic is very useful if you just need True or False, and not complicated numbers or sentences. Having integers and strings make math easier to do, especially if you want 5 to be '5' and not a number.
3.  Why can't everything be represented with an integer?
Because some things aren't integers? Floats aren't integers and neither are strings. Integers can be used in math, but it would fail if you tried to use integers as strings. 

No comments:

Post a Comment