For debian based systems we want to run the following code
sudo apt-get install python3
For windows you can refer to: https://www.youtube.com/watch?v=Cd5XCrfiSv8&list=PL3GPxPa8j1HwXiyTAKZKCeGx18sTVCKCg&index=1
Python strings are "immutable" which means they cannot be changed after they are created. Since strings can't be changed, we construct new strings as we go, to represent computed values. So for example the expression ('hello' + 'there') takes in the 2 strings 'hello' and 'there' and builds a new string 'hellothere'.
raw strings pass all characaters to stdout and does not perform any special formatting like \n
or \\
In [44]:
new_string = 'This is the first python live session'
In [48]:
new_string
new_string_ = 't' + new_string[1:]
new_string_
Out[48]:
In [40]:
# Unicode strings
u_string = u'A unicode \u018e string \xf1'
u_string
Out[40]:
In [50]:
# ascii string
a_string = 'this\tis a ascii\nstring'
print(a_string)
In [43]:
# r-string or raw string
r_string = r'this is an r \nstring \t'
r_string
Out[43]:
In [6]:
string1 = 'hello'
string2 = 'there'
string3 = 'Mary had a little lamb'
In [52]:
# to get last element
print(string1)
string1[4]
Out[52]:
In [55]:
# to get the THIRD element
print(string2)
string2[2]
Out[55]:
In [56]:
# TO get a range of elements
print(string3)
string3[0:4]
Out[56]:
In [12]:
help(str.split)
In [57]:
print(string3)
string3.split()
Out[57]:
In [58]:
le_falta_la_a = string3.split('a')
le_falta_la_a
Out[58]:
In [13]:
help(str.join)
In [22]:
tiene_la_a = 'a'.join(le_falta_la_a)
tiene_la_a
Out[22]:
In [1]:
string1 = ['this', 'iss', 'a', 'random', 'string']
'*'.join(string1)
Out[1]:
In [23]:
help(str.rstrip)
In [26]:
this_is_a_string = 'adfadfds '
In [27]:
this_is_a_string.rstrip()
Out[27]:
In [29]:
left_spaces = ' adgfgfsgsfdgsr'
left_spaces
Out[29]:
In [30]:
left_spaces.lstrip()
Out[30]:
In [31]:
help(str.rfind)
In [59]:
print(string3)
string3.rfind('had ')
Out[59]:
How to build strings properly.
In [66]:
'{one}{one}{one}'.format(one=5,three=3, two=4)
Out[66]:
In [62]:
stringgggg = '%d%d%d' % (5,4,3)
print(stringgggg)