This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Command-line arguments are always strings. | |
| # If we know that an argument is actually an integer, then we have to do the conversion ourselves. | |
| # The first command-line argument is a string s, and the second command-line argument is an integer n. | |
| # Output n copies of s on a single line. | |
| import sys | |
| s = sys.argv[1] # s is a string | |
| n = int(sys.argv[2]) # n is an integer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| i = 0 | |
| while i < len(sys.argv): | |
| print i, sys.argv[i] | |
| i = i + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| print sys.argv[0] # the name of the current script | |
| print sys.argv[1] # the first command-line argument | |
| print sys.argv[2] # the second command-line argument | |
| print sys.argv[3] # the third command-line argument | |
| # ... and so on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [6, 3, 7, 8, 3, 7, 8, 2] | |
| a[1:] # [3, 7, 8, 3, 7, 8, 2] | |
| a[2:4] # [7, 8] | |
| a[:] # [6, 3, 7, 8, 3, 7, 8, 2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| i = 0 | |
| while i < len(a)/2: | |
| tmp = a[i] | |
| a[i] = a[len(a) - i - 1] | |
| a[len(a) - i - 1] = tmp | |
| i = i + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lines = [] | |
| line = raw_input() | |
| while line != "end": | |
| lines.append(line) | |
| line = raw_input() | |
| i = 0 | |
| while i < len(lines): | |
| print lines[len(lines) - i - 1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [1, 2, 3, 4] | |
| a.pop() # 4 | |
| # a is now [1, 2, 3] | |
| a.pop() # 3 | |
| # a is now [1, 2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [] | |
| line = raw_input() | |
| while line != "end": | |
| a.append(line) | |
| line = raw_input() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [1, 2] | |
| a.append(3) | |
| print a # [1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # a = [ 10, 20, 3, 17, 100 ] | |
| a = [ -10, -20, -3, -17, -100 ] | |
| maximum = a[0] | |
| i = 1 | |
| while i < len(a): | |
| if maximum < a[i]: | |
| maximum = a[i] | |
| i = i + 1 |