77 lines
1.0 KiB
Plaintext
77 lines
1.0 KiB
Plaintext
Let's play with builtin types
|
|
=============================
|
|
|
|
- type int, float, bool, str
|
|
- type sequence list, tuple
|
|
- type dict
|
|
|
|
- list.append
|
|
- dict...
|
|
|
|
- strings_
|
|
- formating_
|
|
|
|
.. _strings: https://realpython.com/python-strings/
|
|
.. _formating: https://realpython.com/python-string-formatting/
|
|
|
|
The prompt is a calculator
|
|
---------------------------
|
|
|
|
>>> x = 1
|
|
>>> y =2
|
|
>>> x > y
|
|
False
|
|
>>> x == y
|
|
False
|
|
>>> x != y
|
|
True
|
|
|
|
The strings
|
|
-----------
|
|
|
|
>>> s = "bla bla"
|
|
'bla bla'
|
|
>>> s = 'bla bla'
|
|
'bla bla'
|
|
>>> s = " 'bli bli' "
|
|
>>> s
|
|
" 'bli bli' "
|
|
>>> s = """ sdfsdf "bla bla" sdfsdf"""
|
|
>>> s
|
|
' sdfsdf "bla bla" sdfsdf'
|
|
>>>
|
|
>>> s = "bla bla"
|
|
>>> m = "hu hu"
|
|
>>> s + m
|
|
'bla blahu hu'
|
|
>>> m * 3
|
|
'hu huhu huhu hu'
|
|
>>>
|
|
>>> len(m)
|
|
5
|
|
>>>
|
|
>>> m[3]
|
|
'h'
|
|
>>> m[3:5]
|
|
'hu'
|
|
>>>
|
|
|
|
play with `lower()`, `upper()`, `strip()`, `title()`
|
|
`index()`, `find()`, `replace()`
|
|
|
|
|
|
|
|
String templating
|
|
-----------------
|
|
|
|
>>> s = "ssdfsdf {0} sdfsdfsdf {1}".format("blah", "blih")
|
|
|
|
>>> s= 'a'
|
|
>>> t = "abc"
|
|
>>> t.startswith("a")
|
|
True
|
|
>>> l = ['a', 'b', 'c']
|
|
>>> "-".join(l)
|
|
'a-b-c'
|
|
>>>
|