Last active
October 20, 2017 22:39
-
-
Save dencorg/1a1e8c94c25006979bb1896168980b88 to your computer and use it in GitHub Desktop.
This file contains 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
colors = ['red','green','blue', 'yellow'] | |
a_list = [] # κενή λίστα | |
whatever = ['abc', 4.56, [2,3], 'def', 6] | |
print(whatever) | |
print(colors[0]) # 'red' | |
print(colors[1]) # 'green' | |
print(colors[-1]) # 'yellow' | |
colors = ['red','green','blue', 'yellow'] | |
print(colors[1:3]) | |
# ['green', 'blue'] | |
print(colors[1:]) | |
# ['green', 'blue', 'yellow'] | |
print(colors[::2]) | |
# ['red', 'blue'] | |
print(colors[::-1]) | |
# ['yellow', 'blue', 'green', 'red'] | |
print(len(colors)) | |
# 4 | |
print(colors + ['orange', 'purple']) | |
# ['red', 'green', 'blue', 'yellow', 'orange', 'purple'] | |
print(2 * colors) | |
# ['red', 'green', 'blue', 'yellow', 'red', 'green', 'blue', 'yellow'] | |
print('red' in colors) | |
# True | |
print('brown' in colors) | |
# False | |
print(colors) | |
# ['red', 'green', 'blue', 'yellow'] | |
colors.append('brown') | |
print(colors) | |
# ['red', 'green', 'blue', 'yellow', 'brown'] | |
colors.remove('brown') | |
print(colors) | |
# ['red', 'green', 'blue', 'yellow'] | |
for color in colors: | |
print(color, end=" ") | |
# red green blue yellow | |
for color in colors: | |
print(color.upper(), end=" ") | |
# RED GREEN BLUE YELLOW | |
colors.sort() | |
print(colors) | |
# ['blue', 'green', 'red', 'yellow'] | |
colors.pop() | |
print(colors) | |
# ['blue', 'green', 'red'] | |
[2, 3, 4, 5, 4].count(4) # 2 | |
colors = ['blue', 'green', 'red'] | |
colors.insert(1, 'yellow') | |
print(colors) | |
# ['blue', 'yellow', 'green', 'red'] | |
# μετατροπή συμβολοσειράς σε λίστα | |
word = 'Python' | |
list(word) | |
# ['P', 'y', 't', 'h', 'o', 'n'] | |
# μετατροπή λίστας σε συμβολοσειρά | |
words = ['hello', 'word'] | |
" ".join(words) | |
# 'hello world' | |
# tuples | |
a = (1 , 'asdf', 3.14) | |
print(a) | |
location = ('pos4work', 'patra', 'greece') | |
print(location[0]) | |
location[0] = 'other' # error - δεν αλλάζει τιμή | |
for part in location: | |
print(part, end=' ') | |
# pos4work patra greece |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment