1 / 19

Rezervirane besede

Rezervirane besede. False class finally is return None continue for lambda try True def from nonlocal while. and del global not with as elif if or yield assert. else import pass break except in raise. Komentar. # komentar

hoai
Download Presentation

Rezervirane besede

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rezervirane besede • False • class • finally • is • return • None • continue • for • lambda • try • True • def • from • nonlocal • while • and • del • global • not • with • as • elif • if • or • yield • assert • else • import • pass • break • except • in • raise

  2. Komentar • # komentar • dd=1 #komentar je tudi to • #še en komentar

  3. Python kot kalkulator >>> 2+2 4 >>> #to je komentar >>> 2+2 #komentar seštevanja 4 >>> (50-5*5)/4 6.25 >>> 8/5 1.6 >>> 2/3 0.6666666666666666 >>>

  4. modul in ostanek MOD – DIV >>> 7//3 celo del pri deljenju 2 >>> 7%3 ostanek pri deljenju 1 >>> Primeri!!!

  5. Prirejanje Pazite na presledek >>>visina=20 SyntaxError: invalid syntax (<pyshell#10>, line 1) >>> visina = 20 >>> sirina = 30 >>> visina*sirina 600

  6. Večkratno prirejanje >>> x = y = z = 0 >>> x 0 >>> y 0 >>> z 0 >>>

  7. Kompleksna števila >>> 1j*1J (-1+0j) >>> 1j*complex(1, 1) (-1+1j) >>> (1+2j)*(-2.2+3j) (-8.2-1.4000000000000004j) >>> print((1+2j)*(-2.2+3j)) (-8.2-1.4j) >>> a=1.5+0.4j >>> a.real >>> abs(a) 1.5 1.5524174696260022 >>> a.imag 0.4

  8. V interaktivnem načinu je zadnji rezultat vedno kot spremenljivka_ >>> davek = 19/100 >>> cena = 100.50 >>> davek*cena 19.095 >>> cena + _ 119.595 >>> round(_,2) 119.59 >>>

  9. Delo z nizi >>> beseda = 'pomoč' + 'A' >>> beseda 'pomočA‘ >>> '<' + beseda*5 + '>' '<pomočApomočApomočApomočApomočA>' >>> 'niz' 'anje' 'nizanje‘ >>> 'niz'.strip() + 'anje' 'nizanje'

  10. Delo z nizi 2 (oštevilčenje od 0 do n-1) >>> beseda = "AbRaKaDaBrA" >>> beseda 'AbRaKaDaBrA‘ >>> beseda[4] # četrti element 'K' >>> beseda[0:4] # od prvega do četrtega 'AbRa‘ >>> beseda[:2] #prva dva elementa 'Ab‘ >>> beseda[2:] #vse razen prvih dveh 'RaKaDaBrA' >>>

  11. Nizi 2 >>> beseda[-0] # zadnji znak 'A' >>> beseda[-2:] #zadnja dva znaka 'rA' >>> beseda[:-2] #vse razen zadnjih dveh 'AbRaKaDaB' >>> len(beseda) #dolžina niza 11

  12. Seznami >>> a = ['jajca ', 'na ', 'oko', 100, 34.45] >>> a ['jajca ', 'na ', 'oko', 100, 34.45] >>> a[0] #prvi element 'jajca ' >>> a[-2] #predzadnji element 100 >>> 3*a[:3] + ['boom!+'] #3x izpis in niz boom ['jajca ', 'na ', 'oko', 'jajca ', 'na ', 'oko', 'jajca ', 'na ', 'oko', 'boom!+'] >>> a[3] = a[3]+25 # četrti !!! element povečamo za 25 >>> a ['jajca ', 'na ', 'oko', 125, 34.45] >>> izpis

  13. Zamenjava, vgnezden seznam >>> a[0:2] = [1,2] #zamenjava prvega in drugega elementa!!!!!! >>> a [1, 2, 'oko', 125, 34.45] >>> a[2] = [] >>> a [1, 2, [], 125, 34.45] >>> q = [2, 3] >>> p = [1, q, 4] #vgnezden seznam >>> p [1, [2, 3], 4]

  14. Dodajanje v seznam >>> p[1].append('dodano') >>> p [1, [2, 3, 'dodano'], 4] >>> q [2, 3, 'dodano'] >>>

  15. Prvi programček - Fibonacci >>> #fibonacci >>> a, b = 0, 1 >>> while b < 10: print (b) a, b = b, a+b 1 1 2 3 5 8

  16. Print funkcija >>> i = 10.23 >>> print('vrednost števila i je ',i) vrednost števila i je 10.23 >>> a, b = 0, 1 >>> while b < 1000: print (b, end=' ') a, b = b, a+b 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 >>> Beseda END prepreči skok v novo vrstico

  17. If stavek >>> x = int(input(“Vpišite celo število: ")) Vpišite celo število: : 42 >>> if x < 0: ... x = 0 ... print(‘negativno spremenjeno v nič') ... elif x == 0: ... print(‘nič') ... elif x == 1: ... print(‘samski') ... else: ... print(‘več') ... More

  18. For stavek a = ['cat', 'window', 'defenestrate'] for x in a: print(x, len(x)) cat 3 window 6 defenestrate 12 Izpis elementov in njihove dolžine Zamik krmili stavke

  19. Range, for, break >>> for i in range(5): ... print(i) ... 0 1 2 3 4 for n in range(2, 10): for x in range(2, n): if n % x == 0: print(n, 'enako', x, '*', n//x) break else: # loop fell through without finding a factor print(n, ' je praštevilo')

More Related