print('Привет, Python!')
Привет, Python!
1
1
1 + 2
3
2 - 3
-1
3 * 4
12
4 / 5
0.8
type(4 / 5)
float
4 // 5
0
5 ** 6
15625
6 % 7
6
a = 1
a += 1
a
2
a++
File "<ipython-input-11-bdceb1bc89e4>", line 1 a++ ^ SyntaxError: invalid syntax
++a
2
a = int()
a
0
2 ** 1024
179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216
True
True
False
False
not True
False
True and False
False
False or True
True
1 == 2
False
1 != 2
True
1 is 1
True
0.2
0.2
1E-2
0.01
float('+inf')
inf
2.3j + 4
(4+2.3j)
s = 'Привет, Python!'
"qwer"
'qwer'
s[0]
'П'
s[1]
'р'
len(s)
15
s[len(s) - 1]
'!'
s[-1]
'!'
s[-2]
'n'
type(s[0])
str
s[1:3]
'ри'
s[:6]
'Привет'
s[8:]
'Python!'
s[8:-1]
'Python'
s[::2]
'Пие,Pto!'
s[::-1]
'!nohtyP ,тевирП'
s + '!!!'
'Привет, Python!!!!'
s * 10
'Привет, Python!Привет, Python!Привет, Python!Привет, Python!Привет, Python!Привет, Python!Привет, Python!Привет, Python!Привет, Python!Привет, Python!'
'Py' in s
True
s.<tab>
s.capitalize
s.casefold s.find s.isdecimal s.isspace s.lstrip s.rjust s.startswith s.zfill
s.center s.format s.isdigit s.istitle s.maketrans s.rpartition s.strip
s.count s.format_map s.isidentifier s.isupper s.partition s.rsplit s.swapcase
s.encode s.index s.islower s.join s.replace s.rstrip s.title
s.endswith s.isalnum s.isnumeric s.ljust s.rfind s.split s.translate```
s.find?
Type: builtin_function_or_method
String form: <built-in method find of str object at 0x1108dd718>
Docstring:
S.find(sub[, start[, end]]) -> int
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
s.find('привет')
-1
s.lower().find('привет')
0
for e in s:
print(e)
П р и в е т , P y t h o n !
b = b'abc'
b[0]
97
b[1]
98
b[2]
99
b'текст'
File "<ipython-input-5-102b35411efc>", line 1 b'текст' ^ SyntaxError: bytes can only contain ASCII literal characters.
b = b'\x00\xff'
b[0]
0
b[1]
255
s = 'Привет, Python!'
s.encode?
Type: builtin_function_or_method
String form: <built-in method encode of str object at 0x108bb68b8>
Docstring:
S.encode(encoding='utf-8', errors='strict') -> bytes
Encode S using the codec registered for encoding. Default encoding is 'utf-8'. errors may be given to set a different error handling scheme. Default is 'strict' meaning that encoding errors raise a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
s.encode()
b'\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82, Python!'
s.encode('cp1251')
b'\xcf\xf0\xe8\xe2\xe5\xf2, Python!'
b = s.encode('cp1251')
s2 = b.decode('cp1251')
s2
'Привет, Python!'
t = 1, 'asdf', True, 0.1, 4j, b'abc'
t
(1, 'asdf', True, 0.1, 4j, b'abc')
t[0]
1
t[0]
1
t[1]
'asdf'
u = 1, t
u
(1, (1, 'asdf', True, 0.1, 4j, b'abc'))
u[0]
1
u[1]
(1, 'asdf', True, 0.1, 4j, b'abc')
u[1][1]
'asdf'
t = tuple()
t
()
t = ()
t
()
t = (1)
t
1
t = 1,
t
(1,)
print(1, 2, 3)
1 2 3
print((1, 2, 3))
(1, 2, 3)
a = [1, '2', 3]
a[0] = False
a
[False, '2', 3]
a[1] = [3, 4, 5]
a
[False, [3, 4, 5], 3]
a[1][0]
3
a.<tab>
a.append a.clear a.copy a.count a.extend a.index a.insert a.pop a.remove a.reverse a.sort
b = bytearray(b'abc')
b[0] = 100
b
bytearray(b'dbc')
b.<tab>
b.append
b.capitalize b.endswith b.insert b.istitle b.maketrans b.rfind b.split b.translate
b.center b.expandtabs b.isalnum b.isupper b.partition b.rindex b.splitlines b.upper
b.clear b.extend b.isalpha b.join b.pop b.rjust b.startswith b.zfill
b.copy b.find b.isdigit b.ljust b.remove b.rpartition b.strip
b.count b.fromhex b.islower b.lower b.replace b.rsplit b.swapcase```
s = {1, 2, 1}
s
{1, 2}
s = {1, True, 0.1, 2j, 'asdf', b'abc', (1, 2)}
s
{(1, 2), 0.1, True, 2j, b'abc', 'asdf'}
s = {}
type(s)
dict
s = set()
s
set()
s = {[]}
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-5-889faf072b04> in <module>() ----> 1 s = {[]} TypeError: unhashable type: 'list'
{set()}
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-6-9acc59e59f6f> in <module>() ----> 1 {set()} TypeError: unhashable type: 'set'
s = {1, True, 0.1, 2j, 'asdf', b'abc', (1, 2)}
s.<tab>
s.add
s.clear s.intersection s.pop s.update
s.copy s.intersection_update s.remove
s.difference s.isdisjoint s.symmetric_difference
s.difference_update s.issubset s.symmetric_difference_update```
fs = frozenset({1, 2, 3, 4})
fs
frozenset({1, 2, 3, 4})
{fs}
{frozenset({1, 2, 3, 4})}
for e in fs:
print(e)
1 2 3 4
d = {}
d
{}
d = {'one': 1, 'two': 2}
d['one']
1
d['two'] = 10
d
{'one': 1, 'two': 10}
for k in d:
print(k, d[k])
one 1 two 10
d.<tab>
d.clear
d.copy d.get d.keys d.popitem d.update ```
d.items()
dict_items([('one', 1), ('two', 10)])
d.keys()
dict_keys(['one', 'two'])
d.values()
dict_values([1, 10])
for k, v in d.items():
print(k, v)
one 1 two 10
d = {1: []}
d
{1: []}
d = {[]: 2}
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-10-2c64e5fa0136> in <module>() ----> 1 d = {[]: 2} TypeError: unhashable type: 'list'
hash('asdf')
2456217102423620831
hash([])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-12-6420c1e61a67> in <module>() ----> 1 hash([]) TypeError: unhashable type: 'list'