Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_alx_pcz
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
kurs_alx_pcz
Commits
e6ff34fe
Commit
e6ff34fe
authored
Dec 12, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
różne dopiski do klas technicznie
parent
e1d554b9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
8 deletions
+17
-8
enkapsulacja.py
dzien5/wyjatki/enkapsulacja.py
+5
-0
atrybuty.py
dzien9/klasy_technicznie/atrybuty.py
+6
-3
atrybuty_klasowe_2.py
dzien9/klasy_technicznie/atrybuty_klasowe_2.py
+3
-0
referencje1.py
dzien9/klasy_technicznie/referencje1.py
+2
-1
uwaga_parametr_domyslny3.py
dzien9/klasy_technicznie/uwaga_parametr_domyslny3.py
+1
-4
No files found.
dzien5/wyjatki/enkapsulacja.py
View file @
e6ff34fe
...
...
@@ -40,6 +40,10 @@ class Konto:
raise
BrakSrodkow
(
self
.
_numer
,
kwota
,
self
.
_saldo
)
self
.
_saldo
-=
kwota
@property
def
saldo
(
self
):
return
self
.
_saldo
konto
=
Konto
(
1
,
'Ala'
,
1000
)
print
(
konto
)
...
...
@@ -47,6 +51,7 @@ konto.wplata(200)
print
(
konto
)
konto
.
wyplata
(
800
)
print
(
konto
)
print
(
konto
.
saldo
)
try
:
konto
.
wplata
(
-
50
)
...
...
dzien9/klasy_technicznie/atrybuty.py
View file @
e6ff34fe
...
...
@@ -9,7 +9,7 @@ print(a)
# Do obiektu można dodać atrybut, nawet, gdy nie było o nim mowy w treści klasy.
a
.
imie
=
'Ala'
a
.
wiek
=
30
print
(
a
.
imie
)
print
(
a
.
imie
,
a
.
wiek
)
aa
=
A
()
# print(aa.imie)
...
...
@@ -23,7 +23,10 @@ class Osoba:
o
=
Osoba
(
'Jan'
,
'Kowalski'
,
40
)
o
.
numer_buta
=
44
print
(
'Osoba'
,
o
.
imie
,
'nosi buty'
,
o
.
numer_buta
)
print
()
# Każdy obiekt ma powiązany słownik atrybutów
slownik
=
o
.
__dict__
print
(
slownik
)
...
...
@@ -34,8 +37,8 @@ print(slownik)
slownik
[
'wiek'
]
+=
10
slownik
[
'telefon'
]
=
'321321321'
print
(
o
.
wie
k
)
print
(
o
.
telefon
)
print
(
slowni
k
)
print
(
o
.
imie
,
o
.
wiek
,
o
.
telefon
)
print
()
# Przykład zastosowania: wypisywanie wszystkich pól obiektu jako linii tekstu "a la CSV"
...
...
dzien9/klasy_technicznie/atrybuty_klasowe_2.py
View file @
e6ff34fe
...
...
@@ -67,6 +67,9 @@ print(b.lista)
a
.
lista
.
append
(
'Ala'
)
b
.
lista
.
append
(
'Ola'
)
Klasa
.
lista
.
append
(
'Ela'
)
# nawet ten sam operator +=, który dla inta powodował "oderwanie się" atrybutu od klasy i stworzenie nowego w obiekcie
# dla listy działa inaczej, bo += dla listy jest implementowane jak `extend`
a
.
lista
+=
[
'Karol'
,
'Krzysztof'
]
print
(
a
.
lista
)
print
(
b
.
lista
)
...
...
dzien9/klasy_technicznie/referencje1.py
View file @
e6ff34fe
...
...
@@ -31,7 +31,8 @@ print()
# Aby ostatecznie stracić referencję do obiektu, można też do zmiennej przypisać None
a
=
b
=
None
# W Pythonie można też jawnie usunąć zmienną
# W Pythonie można też jawnie usunąć zmienną.
# To nie jest usunięcie obiektu, tylko zmiennej.
del
c
# To usuwa zmienną, a nie obiekt. Obiekt na normalnych zasadach MOŻE być postprzątany przez garbage collecotra.
...
...
dzien9/klasy_technicznie/uwaga_parametr_domyslny3.py
View file @
e6ff34fe
...
...
@@ -8,10 +8,7 @@ class Student:
def
init_inna_wersja
(
self
,
imie
,
nazwisko
,
oceny
=
None
):
self
.
imie
=
imie
self
.
nazwisko
=
nazwisko
if
oceny
:
self
.
oceny
=
list
(
oceny
)
else
:
self
.
oceny
=
[]
self
.
oceny
=
list
(
oceny
)
if
oceny
else
[]
def
dodaj_ocene
(
self
,
ocena
):
self
.
oceny
.
append
(
ocena
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment