print("Hello, world!")
Hello, world!
2 + 2
4
2 * 2
4
2 + 2 * 2
6
2 ** 10000
19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376L
3 / 2
1
3 // 2
1
3 // 10
0
# найти k и r, такие, что a = b * k + r и 0 <= r < b
float(3) / 2
1.5
3.0 / 2
1.5
3. / 2
1.5
1 / 2 * 5 / float(7)
0.0
3 % 2
1
a = "Hello"
b = a
type(a)
str
a = 3.14
type(a)
float
a = True
b = False
type(a)
bool
a = None
a = 1 + 2j
type(None)
NoneType
1 + 2i
File "<ipython-input-25-34eb3174c9c6>", line 1 1 + 2i ^ SyntaxError: invalid syntax
a
(1+2j)
a ** 2
(-3+4j)
s
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-28-f4d5d0c0671b> in <module>() ----> 1 s NameError: name 's' is not defined
s = "Hello, world!"
len(s)
13
s[0]
'H'
s[1]
'e'
s[12]
'!'
s[-1]
'!'
s[-2]
'd'
s[-13]
'H'
s[-14]
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-37-e52803337a7f> in <module>() ----> 1 s[-14] IndexError: string index out of range
s[13]
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-38-9dedc7505b1b> in <module>() ----> 1 s[13] IndexError: string index out of range
s
'Hello, world!'
print(s)
Hello, world!
s[5]
','
s[-8]
','
s[7:12]
'world'
s[0:3]
'Hel'
s
'Hello, world!'
s[0:-1]
'Hello, world'
s[-1]
'!'
s[7:13]
'world!'
s[7:]
'world!'
s[:-1]
'Hello, world'
s[-2:2]
''
s[-10:10]
'lo, wor'
s[:]
'Hello, world!'
s
'Hello, world!'
s[11:2:-1]
'dlrow ,ol'
s[::-1]
'!dlrow ,olleH'
s
'Hello, world!'
s[6]
' '
print(s[6])
print(repr(s[6]))
' '
s
'Hello, world!'
s.lower()
'hello, world!'
s
'Hello, world!'
s.upper()
'HELLO, WORLD!'
ss
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-69-a543b9622f7b> in <module>() ----> 1 ss NameError: name 'ss' is not defined
s s
File "<ipython-input-70-cf05d884419b>", line 1 s s ^ SyntaxError: invalid syntax
s
'Hello, world!'
len(s)
13
f = len
f(s)
13
s.upper
<function upper>
f = s.upper
f()
'HELLO, WORLD!'
s + s
'Hello, world!Hello, world!'
s - s
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-81-6bf4fbc06009> in <module>() ----> 1 s - s TypeError: unsupported operand type(s) for -: 'str' and 'str'
s * 3
'Hello, world!Hello, world!Hello, world!'
(s + " ") * 3
'Hello, world! Hello, world! Hello, world! '
s ** 2
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-84-12a48625ebb6> in <module>() ----> 1 s ** 2 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
s * 0
''
s * (-1)
''
a = [123, 3.14, True, "Hello", [1, 2, 3]]
print(a)
[123, 3.14, True, 'Hello', [1, 2, 3]]
len(a)
5
a[0]
123
a[1]
3.14
a[-1]
[1, 2, 3]
a[-1][0]
1
a[::-1]
[[1, 2, 3], 'Hello', True, 3.14, 123]
a
[123, 3.14, True, 'Hello', [1, 2, 3]]
a[0] = 156
a
[156, 3.14, True, 'Hello', [1, 2, 3]]
a[0] = a
a
[[...], 3.14, True, 'Hello', [1, 2, 3]]
type(a)
list
del a[0]
a
[3.14, True, 'Hello', [1, 2, 3]]
a.append(7)
a
[3.14, True, 'Hello', [1, 2, 3], 7]
a.insert?
a.insert(2, "Tram-pam-pam")
a
[3.14, True, 'Tram-pam-pam', 'Hello', [1, 2, 3], 7]
a[2:4] = [7, 8, 9]
a
[3.14, True, 7, 8, 9, [1, 2, 3], 7]
a[2:2] = ["Tram-pam-pam"]
a
[3.14, True, 'Tram-pam-pam', 7, 8, 9, [1, 2, 3], 7]
a.sort()
a
[True, 3.14, 7, 7, 8, 9, [1, 2, 3], 'Tram-pam-pam']
a[2:2] = [[1,2,3]]
a
[True, 3.14, [1, 2, 3], 7, 7, 8, 9, [1, 2, 3], 'Tram-pam-pam']
a.append(0)
a.sort()
a
[0, True, 3.14, 7, 7, 8, 9, [1, 2, 3], [1, 2, 3], 'Tram-pam-pam']
s = "Hello, world!"
list(s)
['H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!']
" ".join(["a", "b", "c"])
'a b c'
"*".join(["a", "b", "c"])
'a*b*c'
"".join(["a", "b", "c"])
'abc'
print("\n".join(["a", "b", "c"]))
a b c
s = "Faculty of computer science of Higher school of economics"
s.split()
['Faculty', 'of', 'computer', 'science', 'of', 'Higher', 'school', 'of', 'economics']
"__".join(s.split(" "))
'Faculty__of__computer__science__of__Higher__school__of__economics'
s = raw_input()
2015
len(s)
4
type(s)
str
s + 1
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-140-732b0178cce2> in <module>() ----> 1 s + 1 TypeError: cannot concatenate 'str' and 'int' objects
int(s) + 1
2016
int("hello")
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-143-045de671ab8a> in <module>() ----> 1 int("hello") ValueError: invalid literal for int() with base 10: 'hello'
int("123hello")
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-144-53e52ff22bcf> in <module>() ----> 1 int("123hello") ValueError: invalid literal for int() with base 10: '123hello'
int("a")
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-145-91097a4105a2> in <module>() ----> 1 int("a") ValueError: invalid literal for int() with base 10: 'a'
int("ff", 16)
255
a
[0, True, 3.14, 7, 7, 8, 9, [1, 2, 3], [1, 2, 3], 'Tram-pam-pam']
for item in a[1:]:
print(item, end=" ")
File "<ipython-input-153-ee16b74a97d9>", line 2 print(item, end=" ") ^ SyntaxError: invalid syntax