mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 14:50:19 +00:00
Merge pull request #1093 from matheusfelipeog/feat/py2-to-py3-in-structure-section
Update examples to Python 3 in structure section
This commit is contained in:
@@ -788,7 +788,7 @@ compute x + 1, you have to create another integer and give it a name.
|
||||
|
||||
my_list = [1, 2, 3]
|
||||
my_list[0] = 4
|
||||
print my_list # [4, 2, 3] <- The same list has changed
|
||||
print(my_list) # [4, 2, 3] <- The same list has changed
|
||||
|
||||
x = 6
|
||||
x = x + 1 # The new x is another object
|
||||
@@ -822,7 +822,7 @@ most idiomatic way to do this.
|
||||
nums = ""
|
||||
for n in range(20):
|
||||
nums += str(n) # slow and inefficient
|
||||
print nums
|
||||
print(nums)
|
||||
|
||||
**Better**
|
||||
|
||||
@@ -832,7 +832,7 @@ most idiomatic way to do this.
|
||||
nums = []
|
||||
for n in range(20):
|
||||
nums.append(str(n))
|
||||
print "".join(nums) # much more efficient
|
||||
print("".join(nums)) # much more efficient
|
||||
|
||||
**Best**
|
||||
|
||||
@@ -840,7 +840,7 @@ most idiomatic way to do this.
|
||||
|
||||
# create a concatenated string from 0 to 19 (e.g. "012..1819")
|
||||
nums = [str(n) for n in range(20)]
|
||||
print "".join(nums)
|
||||
print("".join(nums))
|
||||
|
||||
One final thing to mention about strings is that using ``join()`` is not always
|
||||
best. In the instances where you are creating a new string from a pre-determined
|
||||
|
||||
Reference in New Issue
Block a user