Version 4 (modified by 13 years ago) (diff) | ,
---|
Python
Prvi program
- Odpremo IDLE (Python GUI) in odtipkamo naslednjo vrstico
print "Hello, world!"
- Pred shranjevanjem v IDLE še nastavimo Options->Configure Idle->General->Sefault Source Encoding->UTF-8.
- Shranimo datoteko z ukazom File->Save->hello.py
- Poženemo skript z F5 ali Run->Run Module
Drugi program
Jezik nekoliko bolje predstavimo z drugim programom, ki vsebuje funkcijo in bere
# drugi program import math def ploscina(d): return math.pi*d**2/4 d = input("Vnesi premer kroga: ") print u"Ploščina kroga je %.2f" % ploscina(d)
Osnove pythona
Spremenljivke
Vse spremenljivke so nakako avtomatske. Torej so generirane ob prvi uporabi. Tako imamo lahko par različih (osnovnih) tipov kot so:
- integer (int, short, cardinal)- cela števila
- floating point (real, float, double) - plavajoča vejica
- niz znakov ali string
- bool ali true/false označevanje, ki pa je prav zaprav integer
Sedaj lahko sestavljamo osnovne tipe tu v sestavljene tipe, kot so na primer:
- Array - vektor - matrika - seznam
- Slovarji (map) - dictionay - asociativne matrike
- Terke ali se seznami fiksnih velikosti
- Stukture
Kateri tip se je ob prireditvi podal lahko preveerimo z ukazom
type(tip)
Operatorji
Operirajo s spremenljivkami. Vsak programski jezik ima naor teh stvari in se nerazlikuje od novejših jezikov. Ima paython prav neka lepih operatorev.
Primer:
# -*- coding: cp1250 -*- # komentar se prične z # in veja do konca vrstice i = 1 # celoštevilčna a = 1.2 # realno število t = "besedilo" # niz znakov t2 = 'ni nobene razlike' # razen v prirocnisti c = 1 + 2j # kompleksno # Operatorji na osnovnih tipih print i+1 print a+i print t+str(a)
Attachments (26)
-
pythonzaprogramerje.pdf (625.3 KB) - added by 13 years ago.
Delovna rayličica knjige Janeza Demšarja
- Vaja128.png (15.8 KB) - added by 11 years ago.
-
vaja129.png (15.8 KB) - added by 11 years ago.
Vaja 129
- DN130.png (142.9 KB) - added by 11 years ago.
- DN131.png (135.9 KB) - added by 11 years ago.
- DN132.png (135.7 KB) - added by 11 years ago.
- DN133.png (138.8 KB) - added by 11 years ago.
- DN134.png (162.3 KB) - added by 11 years ago.
- DN135.png (141.1 KB) - added by 11 years ago.
- DN136.png (114.9 KB) - added by 11 years ago.
- DN137.png (146.8 KB) - added by 11 years ago.
- DN138.png (125.4 KB) - added by 11 years ago.
- DN139.png (193.6 KB) - added by 11 years ago.
- DN140.png (151.8 KB) - added by 11 years ago.
- sotor.svg (3.6 KB) - added by 11 years ago.
- klop.svg (3.9 KB) - added by 11 years ago.
- plezalnik.svg (4.8 KB) - added by 11 years ago.
-
Py4Inf-01-Introduction.pptx (1.8 MB) - added by 9 years ago.
Uvod v Python slidi
-
Py4Inf-02-Expressions.pptx (429.2 KB) - added by 9 years ago.
Python expressions slidi
-
Py4Inf-03-Conditional.pptx (273.0 KB) - added by 9 years ago.
Conditional slidi
- Uvod_v_Python-Funkcije_in_Globalne_Spremenljivke.pdf (212.1 KB) - added by 9 years ago.
- Uvod_v_Python-Delo_z_Datotekami_Razredi_in_objekti.pdf (270.6 KB) - added by 9 years ago.
- Uvod_v_Python-Seznami_Matrike_Terke_in_Slovarji.pdf (206.7 KB) - added by 9 years ago.
-
DN125_1.png (12.0 KB) - added by 8 years ago.
Primer mreže za vajo 125.
-
DN125_2.png (46.1 KB) - added by 8 years ago.
Primer 3D modela za vajo 125.
-
vaja300.PNG (19.8 KB) - added by 5 years ago.
Better figure for vaja300 (in vaja129.png one dimension is mission and one dimension is faulty (22)).