Thursday, December 4, 2014

1.3.5 Strings

Strings

Tweet

Conclusion:
1.       How many characters are in this sentence? Does it matter whether Python is storing the string as one byte per character or four bytes per character?

   
       There are 41 charactres in that sentence. Yes because unicode uses four bytes per character, and ASCII uses one byte per character. Unicode offers a wider range of characters.

2.      This question asks you about something you have not learned. In fact, the question is asking about details that go beyond what you will learn in this course. However, wondering what is going on at a lower level of abstraction – and talking about it – can be a useful strategy when learning about computing.

Describe what you think occurs in memory when the following code is executed.

In []: a = 'one string'
In []: b = 'another'
In []: c = a[:3] + ' and ' + b
In []: print(c[6:10])

012345678901234           
one_and_another
dan
What occurs in this memory when this code is executed is first a equals the phrase ' one string '. Then, b equals the word another. Next c is going to equal the first 3 characters of a plus ' and' plus b. So c is going to end up equalling ' one _and_ another '. Lastly, the code is going to print the 6th character to the 10th character in c. But its not going to include the 6th and 10th character.


No comments:

Post a Comment