摘要:
It is often useful to swap the values of two variables. With conventional assignments, you have to use a temporary variable. This solution is cumberso... 阅读全文
摘要:
A tuple is a sequence of values. The values can be any type, and they are indexed by integers, so in that respect tuples are a lot like lists. The imp... 阅读全文
摘要:
If you played with the Fibonacci function, you might have noticed that the bigger the argument you provide, the longer the function takes to run. Furt... 阅读全文
摘要:
Lists can appear as values in a dictionary. For example, if you were given a dictionary that maps from letters to frequencies, you might want to inver... 阅读全文
摘要:
If you use a dictionary in a for statement, it traverses the keys of the dictionary. For example, print_hist prints each key and the corresponding val... 阅读全文
摘要:
Suppose you are given a string and you want to count how many times each letters appears. There are several ways you do it:You could create 26 variabl... 阅读全文
摘要:
A dictionary is like a list, but more general. In a list, the indices have to be integers; in a dictionary they can be (almost) any type. You can thin... 阅读全文
摘要:
The slice operator can take a third argument that determines the step size, so t[::2] creates a list that contains every other element from t. If the ... 阅读全文
摘要:
A string is a sequence of characters and a list is a sequence of values, but a list of characters is not the same as a string. To convert from a strin... 阅读全文
摘要:
When you assign an object to a variable, Python copies the reference to the object. In this case a and b refer to the same list.If you want ... 阅读全文