In [ ]:
a = 5
b = 2
c = 5.5
d = 3+2j
e = 3e+4
print(a, b, c, d, e)
In [ ]:
a, b = 5, 2
print(a, b)
a, b = b, a
print(a, b)
In [ ]:
print(5 / 2)
print(5 // 2)
print(5 / 2.0)
print(5 % 2)
print(5 ** 2)
In [ ]:
a, b, c = abs(-2), pow(5, 2), pow(5, 2, 10)
print(a)
print(b)
print(c) # 5 ** 2 % 10
In [ ]:
x = 10
print(5 < x < 100)
print(5 and 2)
print(5 or 2)
In [ ]:
a = 5
a++
In [ ]:
a = 5
a += 1
print(a)
In [ ]:
a = 5
a--
In [ ]:
a = 5
a -= 1
print(a)
In [ ]:
a = "hulajnoga"
b = 'deskorolka'
c = """ala
ma
kota"""
d = """ala \
ma \
kota"""
print(a, b, c, d)
In [ ]:
dlugosc = len("ala ma kota")
print(dlugosc)
print("ala" * 3)
print("ala" " ma" " kota" == "ala ma kota")
In [ ]:
import string
print(string.digits)
print(string.ascii_letters)
print(string.ascii_uppercase)
print(string.ascii_lowercase)
print(string.hexdigits)
In [ ]:
first, middle, last, reversed_name = "ala"[0], "ala"[1:2], "ala"[-1], "andrzej"[::-1]
print("\n".join((first, middle, last, reversed_name)))
In [ ]:
print("{} {} {}".format("ala", "ma", "kota"))
print("{2} {1} {0}".format("ala", "ma", "kota"))
print("{liczbapierwsza} {ala} {ma}".format(liczbapierwsza=7, ala="ala", ma=[1,2]))
In [ ]:
class Punkt():
x = 5
y = 10
slowa = {
"imie": "ala",
"dom": "jednorodzinny",
"wiek": ["27", "lat"],
"lista": [1,2,3,4],
"punkt": Punkt()
}
"{imie} ma {wiek[0]} {wiek[1]} i buduje {dom} dom, współrzędne {punkt.x}, {punkt.y}".format(**slowa)
In [ ]:
a = "ala %s" % "ma kota"
b = "ala %d" % 5
c = "%o" % 111
print(a)
print(b)
print(c)
In [ ]:
print(" ".join(["ala", "ma", "kota"]))
print(" ala ma kota ".strip())
print("ala ma kota".split(" "))
print("ala ma kota".split(sep=" ", maxsplit=1))
print(list("ala ma kota"))
print("ala ma arbuza".replace("arbuza", "kota"))
In [ ]:
zwierze = "kota"
f_string = f'Ala ma {zwierze}'
print(f_string)
In [ ]:
def foo(zwierze):
return f'Ala ma {zwierze}'
def bar():
return f'Ala ma {abc}'
def foobar():
return f'"Ala ma {{ kota }}"'
print(foo("kota"))
print(foo("psa"))
abc = "asd"
print(bar())
print(foobar())
In [ ]:
def sum():
return f'Suma: {value}'
sum()
In [ ]:
def sum(value):
return f'Suma: {value}'
sum(5)
In [ ]:
def foo():
return 42
print(f'ala ma {foo()}')
print('ala ma ' + str(foo()))
print(f'''ala ma {
foo() + 1 + foo()
}''')
Traceback (most recent call last): File "python", line 1, in
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 0: ordinal not in range(128)
In [ ]:
print(b"Ala ma kota")
print(b"Ala ma kota".decode("ascii"))
print("Łabądź".encode("utf-8"))
print("Łabądź".encode("utf-8").decode("utf-8"))
print("Łabądź".encode("utf-8").decode("ascii"))