Wypróbuj w konsoli podane przykłady wyrażeń listowych (ang. list comprehensions) Pythona:
Kod nr
# lista kwadratów liczb od 0 do 9
[x**2 for x in range(10)]
# lista dwuwymiarowa [20,40] o wartościach a
a = int(raw_input("Podaj liczbę całkowtią: "))
[[a for y in xrange(20)] for x in xrange(40)]
# lista krotek (x, y), przy czym x != y
[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]Przećwicz alternatywne spsoby otwierania plików:
Kod nr
f = open('test.txt', 'r')
for line in f:
print line[0]
f.close()
with open("text.txt", "r") as txt:
for line in txt:
print line
for line in open('test.txt', 'r'):
print line[0]Warto odwiedzić:
- http://pl.wikibooks.org/wiki/Zanurkuj_w_Pythonie
- http://brain.fuw.edu.pl/edu/TI:Programowanie_z_Pythonem
- http://pl.python.org/docs/tut/
- http://en.wikibooks.org/wiki/Python_Programming/Input_and_Output
- https://wiki.python.org/moin/HandlingExceptions
- http://learnpython.org/pl
- http://www.checkio.org
- http://www.codecademy.com
- https://www.coursera.org
| Autor: | Robert Bednarz <[email protected]> |
|---|---|
| Utworzony: | 2026-10-13 o 12:29 |