Professional Documents
Culture Documents
Data Types Python
Data Types Python
- can be created using quotes, double quotes or triple quotes (for strings on multiple
lines)
myString = str()
myString = ' '
Empty * myString = " "
myString = """
"""
lower()
upper()
capitalize()
count()
Methods
Methods
find()
rfind()
index()
rindex()
replace()
join()
strip()
lstrip()
rstrip()
split()
rsplit()
del
Reverse a *
* Slicing
Escape sequence
Formatting of *
Strings Lists
of bytes representiong unicode ch -collection of orderd data (items have a defined order
not have a ch data type and that order will not change, if not a method was
ple ch is a string with length of 1 applied)
mmutable (can not be changed after created) - strings created after - are mutable (can be changed using methods, without
enation and methodes are 'new' strings creating a new list)
- allow duplicate values.
e created using quotes, double quotes or triple quotes (for strings on multiple Empty list:
myList = []
myList = list()
ng = str()
ng = ' '
ng = " "
ng = """
"""
ng = "This is a string"
ng2 = " 100"
ng3 = " I am 28 years old "
ng4 = ' 3,14'
ng5 = ' ' - ⚠ is not emplty
s = 'Hello WORLD'
print(s.count('Hello'))
Output: 1
print(s.count('l'))
Output: 2
print(s.count('l', 3, 8))
Output: 1
Syntax: find(value, start, end) index()
- finds the first occurrence of the specified value. Return -1 if value
not found. Same as index(), but difference is that the index()
method raises an exception (error) if value not found.
- value - a string/ substring. Required. The value to search for
- start - Optional. Where to start the search. Default is 0
- end - Optional. Where to end the search. Default is to the end of
the string
print(s.find('Hello'))
Output: 0 - my substr starts with position 0
print(s.find('l'))
Output: 2 - count the first aparence of 'l'
replace() insert()
separator.join(sir) pop()
strip() remove()
reverse()
del s del
sort()
Empty tuple:
myTuple=()
myTuple = tuple()
0
count()
index()
l= [1, 2, 3]
l.append(4)
print(l)
Output: [1, 2, 3, 4]
Set
-collection of unorderd data
- are mutable (can be changed after created, add, remove elements etc.)
- do not allow duplicats values
- unindexed (items do not have a defined order - every time has a different index)
- do not accept booleans if already exist 1 or 0 inside
- can not accept changable elem as lists or dict
Empty set:
mySet = set()
x.update(y)
{1, 2, 3, 'a', 'c', 'b'}
print(x.__len__())
print(len(x))
- can not access elements, no index available
x = {'a', 'b'}
add()
x.add(7) -> {'a', 'b', 7}
update()
clear()
Copy()
difference()
intersection()
union()
pop()
remove()